Django如何从ListVi提交表单

2024-03-28 18:17:59 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图将一个表单传递给django中的ListView来创建一个新对象

有办法吗? (我知道如何用def代替class来实现这一点)

Im使用django 2.0、python3.4

这是ListView:

class CustomerListView(ListView):
    template_name = 'customers/table_customers.html'
    context_object_name = 'items'

    def get_queryset(self):
        return Customer.objects.all()

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

我可以看到页面中的表单,但是当我点击“提交”时,我从服务器得到405响应:“methodnotallowed(POST):/customers/customer/”。在

这是表格:

^{pr2}$

Tags: 对象djangonameself表单datagetreturn