How can I alter this post_detail function:
def post_detail(request):
post = get_object_or_404(Post)
comments = post.comments.filter(active=True)
new_comment = None
if request.method == 'POST':
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
})
So this URL line can read the function?
path('post/<int:pk>/', views.post_detail, name='post-detail'),
Note:
In the Post model get_absolute_url is provided for returning the pk
Thanks in advance