May 2018
Beginner to intermediate
526 pages
11h 57m
English
We have created the functionality to manage comments for a post. Now, we will need to adapt our post/detail.html template to do the following things:
First, we will add the total comments. Open the post/detail.html template and append the following code to the content block:
{% with comments.count as total_comments %} <h2> {{ total_comments }} comment{{ total_comments|pluralize }} </h2>{% endwith %}
We are using the Django ORM in the template, executing the QuerySet comments.count(). Note that Django template language doesn't use parentheses for calling methods. The {% with ...
Read now
Unlock full access