我有Django函数视图,里面有两个窗体。检测用户键入的数据的最佳解决方案是什么?我知道form.is_valid()
是如何工作的,但我仍然想首先检查哪个表单填充了数据。在
我的代码:
def edit_profile_view(request):
if request.method == "POST":
edit_form = EditProfileForm(request.POST)
pass_form = ChangePasswordForm(request.POST)
# here I want to detect which form has data inside,
# and then save this form
else:
edit_form = EditProfileForm()
pass_form = ChangePasswordForm()
template = get_template("profiles/profile_edit.html")
variables = RequestContext(request, {'edit_form': edit_form, 'pass_form': pass_form})
output = template.render(variables)
return HttpResponse(output)
只要表单有两个不同的操作/视图,那么包含数据的表单就是用户单击提交的表单。在
正如您所说,您可以检查表单错误的实际情况,或者在您的表单上为
is_filled_in
创建一个方法,但这一切对我来说似乎太过了。在相关问题 更多 >
编程相关推荐