8000 Update code slightly to remove extra comments and add 'new post' button. · DORELAS/complete-python-course@4407c62 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4407c62

Browse files
committed
Update code slightly to remove extra comments and add 'new post' button.
1 parent 5c8e564 commit 4407c62

File tree

2 files changed

+7
-15
lines changed
  • section14/projects/first-flask-app-lectures

2 files changed

+7
-15
lines changed

section14/projects/first-flask-app-lectures/8-jinja-for-loops/templates/home.jinja2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
We could do this instead:
1515
1616
<ul>
17-
<li><a href="/post/0">{ posts[0]['title'] }</a></li>
17+
<li><a href="/post/0">{ posts[0]['title'] }</a></li> <!-- Make sure to have double curly braces; ommitted here just so it doesn't break the file. -->
1818
<li><a href="/post/1">{ posts[1]['title'] }</a></li>
1919
</ul>
2020

section14/projects/first-flask-app-lectures/9-adding-home-link/templates/home.jinja2

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,13 @@
22

33
{% block content %}
44
<h1>Welcome to your blog.</h1>
5-
<h2>Posts</h2> <!-- Here we've got a slightly smaller heading -->
6-
<ul> <!-- This bullet point list will show a link for each post. -->
7-
{% for post_id, post in posts.items() %} <!-- This is very similar to Python, but it's a Jinja2 for loop—looks the same and even we have .items for the dictionary -->
8-
<li><a href="{{ url_for('post', post_id=post_id) }}">{{ post['title'] }}</a></li> <!-- Here we use url_for to take us to the appropriate route. -->
9-
{% endfor %}
10-
</ul>
11-
{% endblock %}
12-
13-
<!--
14-
We could do this instead:
5+
<h2>Posts</h2>
156

167
<ul>
17-
<li><a href="/post/0">{ posts[0]['title'] }</a></li>
18-
<li><a href="/post/1">{ posts[1]['title'] }</a></li>
8+
{% for post_id, post in posts.items() %}
9+
<li><a href="{{ url_for('post', post_id=post_id) }}">{{ post['title'] }}</a></li>
10+
{% endfor %}
1911
</ul>
2012

21-
But of course, that would give an error if we don't have sufficient posts—and as we add new posts they wouldn't appear in the list.
22-
-->
13+
<a href="{{ url_for('create') }}">Create new post</a>
14+
{% endblock %}

0 commit comments

Comments
 (0)
0