R
R
Ribachok2021-09-04 20:18:03
Django
Ribachok, 2021-09-04 20:18:03

How to insert a form into a ListView?

I have a model

class Notif(models.Model):
    user = models.OneToOneField(User, on_delete=models.CASCADE)
    date = models.DateTimeField(default=timezone.now)
    text = models.CharField(max_length=100)

And in the template, I display all the objects of the model, but the form does not work in any way. The maximum that I could achieve was that the form started to show in the template, but upon confirmation it gives a 405 error. Here is the view
class Home(ListView):
    template_name ='main.html'
    context_object_name = 'p'
    model = Notif

    def get_context_data(self, **kwargs):
        context = super(Home, self).get_context_data(**kwargs)
        context['form'] = Notif()
        return context

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question