The view blog.views.post_detail didn't return an HttpResponse object. It returned None instead
Не получается зайти, после добавления комментариев.
views.py
from django.shortcuts import render, get_object_or_404, redirect
from django.views.generic import ListView
from .models import Post, Comment
from .forms import CommentForm
class PostListView(ListView):
queryset = Post.published.all()
context_object_name = 'posts'
paginate_by = 3
template_name = 'blog/post/list.html'
def post_detail(request, year, month, day, post):
post = get_object_or_404(Post, slug=post, status='published',
publish__year=year, publish__month=month,
publish__day=day)
# comments
comments = post.comments.filter(active=True)
new_comment = None
if request.method == 'POST':
# user send comment
comment_form = CommentForm(data=request.POST)
if comment_form.is_valid():
new_comment = comment_form.save(commit=False)
new_comment.post = post
new_comment.save()
else:
comment_form = CommentForm()
return render(request, 'blog/post/detail.html', {'post': post,
'comments': comments,
'new_comment': new_comment,
'comment_form': comment_form})
detail.html
{% with comments.count as total_comments %}
<h2>{{ total comments }} comment {{ total comments|pluralize }}</h2>
{% endwith %}
{% for comment in comments %}
<div class="comment">
<p class="info">
Comment {{ forloop.counter }} by {{ comment.name }}
{{ comment created }}
</p>
{{ comment.body|linebreaks }}
</div>
{% empty %}
<p>There no comments yet.</p>
{% endfor %}
</div>
{% endblock %}