Skip to content

Commit

Permalink
Merge pull request #74 from kampfschlaefer/add_safe_marker_to_preserv…
Browse files Browse the repository at this point in the history
…e_formatting

use safe and linebreaks filters for the text
  • Loading branch information
oinopion committed Jul 27, 2014
2 parents fe652e8 + 96c48f6 commit b2f170a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
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`.

0 comments on commit b2f170a

Please sign in to comment.