1
我有Django函数视图里面有两种形式。检测哪个表单有用户输入的数据的最佳解决方案是什么?我知道form.is_valid()
是如何工作的,但我仍然首先检查哪些表格填充了数据。如何检查Django表单是否包含任何数据?
我的代码:
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)