Links

We now have three different routes:

  1. http://localhost:5000/talk/new Allows a user to create a new talk, and submit it back to our application.
  2. http://localhost:5000/talk Saves the talk to a database, and shows the user the details about their submitted talk
  3. http://localhost:5000/talks Lists all of the talks that have been submitted.

But we shouldn’t expect a user to know those paths to get to the content. We’ve made a connection from the submission form to the page that shows details about a single talk. But we can link all the pages together. We’re going to update our templates so that each of our views can link to each other.

First we can link from a single talk to all of our talks. Make your templates/talk.html file look like this:

<h1>{ title }}</h1>
<h2>Submitted on {{ timestamp }}</h2>
<p>{{ description }}</p>

<br><br>

<a href="{{ url_for('talks') }}">See all talks</a>

Now after you submit the form at http://localhost:5000/talk/new, you should see a link that leads you to the list of all poems.

You can see the url_for method used here which is a helper for linking between different routes within your application.

Now from your /talks page link back to create a new talk by including the link at the top of templates/talks.html:

<a href="{{ url_for('new_talk') }}">Create New Talk</a>

<h1>My Talks</h1>

{% for talk in talks %}
  <h2>{{ talk.id }}</h2>
  <p>{{ talk.title }}</p>
  <small>submitted on {{ talk.created_at }}</small>
{% endfor %}

Now click back and forth between your list of talks and creation of a new talk.