V
V
Vladislava2021-12-10 17:03:22
Django
Vladislava, 2021-12-10 17:03:22

Why is Django not displaying a form?

Why is my comment form not showing up?

Models:

class Comment(models.Model):
    body = models.TextField()


views:
class AddCommentView(CreateView, LoginRequiredMixin):
    model = Comment
    template_name = 'post_detail.html'
    fields = '__all__'


Forms:
class Comment(ModelForm):
    class Meta:
        model = Comment
        fields = ['body']


URLs:
path('post_detail/', AddCommentView.as_view(), name='add_comment')


template:
<p><form method="POST">
      {% csrf_token %}
      {{ form.as_p }}
      <button>Submit</button>
  </form></p>


Tracebacks did not fly

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladislava, 2021-12-28
@vladis005

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 question

Ask a Question

731 491 924 answers to any question