Answer the question
In order to leave comments, you need to log in
How to save a django comment?
I want to save the comment entered in the form.
https://habrastorage.org/files/a85/f03/9b7/a85f039...
View
def valpost(request, slug = None):
instance = get_object_or_404(Post, slug = slug)
comment = Comment.objects.all()
form = CommentForm(request.POST or None)
context = {
"title": instance.title,
"instance" : instance,
"comment_form": form,
"comments" : comment,
}
template = 'post_detail.html'
return render(request, template, context)
if form.is_valid():
А дальше не знаю как, подскажите
Answer the question
In order to leave comments, you need to log in
def valpost(request, slug = None):
instance = get_object_or_404(Post, slug=slug)
comments = Comment.objects.all()
form = CommentForm()
if request.method == 'POST'
form = CommentForm(request.POST)
if form.is_valid():
form.save()
return redirect(<success page>)
context = {
"title": instance.title,
"instance" : instance,
"form": form,
"comments" : comments,
}
template = 'post_detail.html'
return render(request, template, context)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question