我想让我的FormView
进行验证(显示哪些字段包含错误),并在表单无效时重新使用已经输入的内容
目前,如果表格无效:
似乎get_context_data
使基于类的FormView
的默认行为无效
如何在一个上下文中验证多个表单,以及如何在这样的上下文中重新加载已尝试的表单数据
class ProductFormView(FormView):
template_name = 'product/product_create.html'
model = Product
success_message = f'Product created successfully'
success_url = '/product/list'
def get_context_data(self, **kwargs):
context = super(ProductFormView, self).get_context_data(**kwargs)
context['form_1'] = CommonFieldsForm(instance=self.model())
context['form_2'] = PriceForm(instance=self.model())
return context
def form_invalid(self, form):
response = super().form_invalid(form)
return response
def form_valid(self, form):
response = super().form_valid(form)
return response
目前没有回答
相关问题 更多 >
编程相关推荐