Answer the question
In order to leave comments, you need to log in
Why is Django not displaying a form?
Why is my comment form not showing up?
Models:
class Comment(models.Model):
body = models.TextField()
class AddCommentView(CreateView, LoginRequiredMixin):
model = Comment
template_name = 'post_detail.html'
fields = '__all__'
class Comment(ModelForm):
class Meta:
model = Comment
fields = ['body']
path('post_detail/', AddCommentView.as_view(), name='add_comment')
<p><form method="POST">
{% csrf_token %}
{{ form.as_p }}
<button>Submit</button>
</form></p>
Answer the question
In order to leave comments, you need to log in
Try removing fields = '__all__' and adding form_class=Comment instead. And it is advisable not to combine the paragraph and form tag
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question