Monday, March 30, 2020

Re: Form not displaying

Sure. It's as follows:

@login_required
def add_comment(request, image_id):
template_name = 'add_comment.html'
image = get_object_or_404(Picture, id=image_id)
comments = image.comments.filter(active=True)
new_comment = None
# Comment posted
if request.method == 'POST':
comment_form = CommentForm(data=request.POST)
if comment_form.is_valid():
# Create Comment object and don't save to database yet
new_comment = comment_form.save(commit=False)
# Assign the current post to the comment
new_comment.post = post
# Save the comment to the database
new_comment.save()
else:
comment_form = CommentForm()

return render(request, template_name, {'image': image,
'comments': comments,
'new_comment': new_comment,
'comment_form': comment_form})



Thanks

Jeff

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/8e0f5a28-7a48-4037-aba5-ea591a81d397%40googlegroups.com.

No comments:

Post a Comment