Created
January 27, 2021 17:32
-
-
Save siumhossain/0057676059277ce2e46278dbe02ec0f2 to your computer and use it in GitHub Desktop.
a important comment view for me
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def post_single(request, post): | |
| post = get_object_or_404(Post, slug=post, status='published') | |
| comments = post.comments.filter(status=True) | |
| user_comment = None | |
| if request.method == 'POST': | |
| comment_form = NewCommentForm(request.POST) | |
| if comment_form.is_valid(): | |
| user_comment = comment_form.save(commit=False) | |
| user_comment.post = post | |
| user_comment.save() | |
| return HttpResponseRedirect('/' + post.slug) | |
| else: | |
| comment_form = NewCommentForm() | |
| return render(request, 'single.html', {'post': post, 'comments': user_comment, 'comments': comments, 'comment_form': comment_form}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment