Adding comments to the post detail template
We need to edit the blog/post/detail.html
template to implement the following:
- Display the total number of comments for a post
- Display the list of comments
- Display the form for users to add a new comment
We will start by adding the total number of comments for a post.
Edit the blog/post/detail.html
template and change it as follows:
{% extends "blog/base.html" %}
{% block title %}{{ post.title }}{% endblock %}
{% block content %}
<h1>{{ post.title }}</h1>
<p class="date">
Published {{ post.publish }} by {{ post.author }}
</p>
{{ post.body|linebreaks }}
<p>
<a href="{% url "blog:post_share" post.id %}">
Share this post
</a>
</p>
{% with comments.count as total_comments %}
<h2>
{{ total_comments }} comment{{ total_comments|pluralize }}
</h2>
{% endwith %}
{% endblock %}
We use the Django ORM in...