你好,所以!你知道吗
我有一个奇怪的情况,我不明白。我有一个FormView,用户可以在其中填写用户名或电子邮件来恢复帐户的密码。在视图窗体视图中,我得到以下情况:
class RecoverPassword(FormView):
""" Request password recovery by username or email address """
template_name = "users/recover.html"
form_class = RecoverPasswordForm
def post(self, request, *args, **kwargs):
form = self.form_class(request.POST)
print(form) # <<<--- Removing this results in an error
username = form.cleaned_data.get("username")
if username:
print(username)
return HttpResponseRedirect(self.get_success_url())
这是可行的,并且填充的用户名显示在终端中。 但是,如果我删除以下行:
print(form)
用用户名填写表格,然后点击提交,我得到以下信息 错误:
Exception Type: AttributeError
Exception Value: 'RecoverPasswordForm' object has no attribute 'cleaned_data'
我就是搞不懂为什么会这样。有人知道这是怎么回事吗?提前谢谢!你知道吗
你为什么要在
post
中这样做?改用form_valid
方法:相关问题 更多 >
编程相关推荐