2015-12-01 56 views
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) 

回答

0

只是有两个不同的动作/为形式的意见则有资料的形式是用户点击提交的一个。

你可以像你说的那样,检查表单错误实际上是什么,或者在表单上为is_filled_in制作一个方法,但是这对我来说似乎有点矫枉过正。

相关问题