Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use safe and linebreaks filters for the text #74

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions django_templates/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ It works! But we want them to be displayed in a way we created earlier in the __
<div>
<p>published: {{ post.published_date }}</p>
<h1><a href="">{{ post.title }}</a></h1>
<p>{{ post.text }}</p>
<p>{{ post.text|linebreaks }}</p>
</div>
{% endfor %}

Everything you put between `{% for %}` and `{% endfor %}` will be repeated for each object in the list. Refresh your page:

![Figure 13.3](images/step3.png)

Have you noticed that we used a slightly different notation this time `{{ post.title }}` or `{{ post.text }}`. We are accessing data in each of the fields defined in our `Post` model.
Have you noticed that we used a slightly different notation this time `{{ post.title }}` or `{{ post.text }}`. We are accessing data in each of the fields defined in our `Post` model. Also the `|linebreaks` is piping the posts text through a filter to convert line-breaks into paragraphs.

Congrats! Now go ahead and try adding a new post in your Django admin (remember to add published_date!), then refresh your page to see if the post appears there.

Expand Down
8 changes: 3 additions & 5 deletions template_extending/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Then open it up and copy everything from `post_list.html` to `base.html` file, l
<div class="post">
<p>published: {{ post.published_date }}</p>
<h1><a href="">{{ post.title }}</a></h1>
<p>{{ post.text }}</p>
<p>{{ post.text|linebreaks }}</p>
</div>
{% endfor %}
</div>
Expand Down Expand Up @@ -77,7 +77,7 @@ Now save it, and open your `blog/templates/blog/post_list.html` again. Delete ev
<div class="post">
<p>published: {{ post.published_date }}</p>
<h1><a href="">{{ post.title }}</a></h1>
<p>{{ post.text }}</p>
<p>{{ post.text|linebreaks }}</p>
</div>
{% endfor %}

Expand All @@ -94,13 +94,11 @@ It means that we're now extending `base.html` template in `post_list.html`. Only
<div class="post">
<p>published: {{ post.published_date }}</p>
<h1><a href="">{{ post.title }}</a></h1>
<p>{{ post.text }}</p>
<p>{{ post.text|linebreaks }}</p>
</div>
{% endfor %}
{% endblock content %}

That's it! Check if your website is still working properly :)

> If you have an error `TemplateDoesNotExists` that says that there is no `mysite/base.html` file and you have `runserver` running in the console, try to stop it (by pressing Ctrl+c - Control and C buttons together) and restart it with `python manage.py runserver`.