There is a view with post display and commentary under it. How to add saving comments after adding and clicking on the button?

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) 
https://pp.userapi.com/c626326/v626326759/5797d/XrGKMl1UT8c.jpg

  • docs.djangoproject.com/en/1.10/topics/forms/modelforms / ... I don’t see a call to you to save the entity. form.save - YozhEzhi
  • def valpost (request, slug = None): instance = get_object_or_404 (Post, slug = slug) comment = Comment.objects.all () form = CommentForm (request.POST or None) if form.is_valid (): form.save ( ) context = {"title": instance.title, "instance": instance, "comment_form": form, "comments": comment,} template = 'post_detail.html' return render (request, template, context) get Exception Value : 'CommentForm' object has no attribute 'save' - question1
  • Did you import the form in a file? from myapp.forms import CommentForm - YozhEzhi
  • The problem has already been solved, thanks - question1

0