当用户在视图中填写第一个表单(说明他们是否有在线帐户)并单击submit时,我希望将用户重定向到不同的页面(和不同的表单)。
我已经尝试过这样做了,但是我得到了SupplyTypeForm没有属性cleaned_data
class ServiceTypeView(FormView):
form_class = SupplyTypeForm
template_name = "supplier.html"
success_url = '/'
def post(self, request, *args, **kwargs):
super()
online_account = self.form_class.cleaned_data['online_account']
if online_account:
redirect('../online')
else:
redirect('../offline')发布于 2016-02-01 14:46:31
您应该在form_valid方法中执行此逻辑,该方法将表单作为参数接收。注意,您需要返回要呈现的调用的值,而对super()的调用本身没有任何作用;您必须在该对象上引用一个方法。
def form_valid(self, form):
super().form_valid(form)
online_account = form.cleaned_data['online_account']
if online_account:
return render(request, "supplier_online.html")
else:
return render(request, 'supplier_offline.html')https://stackoverflow.com/questions/35133247
复制相似问题