Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 属性错误:';非类型';对象没有属性';检查密码';django allauth中的错误_Python_Django_Forms_Passwords_Django Allauth - Fatal编程技术网

Python 属性错误:';非类型';对象没有属性';检查密码';django allauth中的错误

Python 属性错误:';非类型';对象没有属性';检查密码';django allauth中的错误,python,django,forms,passwords,django-allauth,Python,Django,Forms,Passwords,Django Allauth,我将django all auth用于我的登录和注册视图以及模板,但我还想实现更改密码功能,因此默认情况下,它有一个我们可以使用的模板password\u change.html,但我需要一个自定义设计,为了不想通过使用内置的allauthpasswordchange视图来刷新页面,所以决定通过在我的视图中导入allauth的ChangePasswordForm表单,只使用allauth的ChangePasswordForm表单 我使用ajax将一个请求发布到url(视图),并返回一个Json响

我将django all auth用于我的登录和注册视图以及模板,但我还想实现更改密码功能,因此默认情况下,它有一个我们可以使用的模板
password\u change.html
,但我需要一个自定义设计,为了不想通过使用内置的
allauth
passwordchange视图来刷新页面,所以决定通过在我的视图中导入allauth的
ChangePasswordForm
表单,只使用allauth的
ChangePasswordForm
表单

我使用ajax将一个请求发布到
url(视图)
,并返回一个
Json响应
,这样我就可以在自定义模板中使用jquery/ajax中的响应

视图.py

from allauth.account.forms import ChangePasswordForm

@login_required
def change_password(request):
    form =  ChangePasswordForm(data=request.POST)
    if form.is_valid():
        form.save()
        result = {'status':'done'}
    else:
        result = {'status':'undone', 'form_errors':form.errors}
    json_data = json.dumps(result)
    return HttpResponse(json_data, 'application/json')
templates.html

$('.form').click(function(){
   $.ajax({
                      type: "POST",
                              url: '/change_password/',
                              data: form_data,
                              success: function(response)
                                {
                                    if(response.status === 'done')
                                        console.log('great====>');
                                    ......
                                    .....   
                        }
                   });   
 });    
我正在分别呈现模板中的字段,如
form.oldpassword、form.newpassword等。
也有错误

因此,当我在没有任何数据的情况下提交表单时,我得到了正确的错误消息,即
此字段是必需的
,但当我只输入了一个字段
oldpassword
并提交表单时,我得到了以下错误

  File "/home/user/Envs/proj/local/lib/python2.7/site-packages/django/forms/forms.py", line 290, in _clean_fields
    value = getattr(self, 'clean_%s' % name)()
  File "/home/user/Envs/proj/local/lib/python2.7/site-packages/allauth/account/forms.py", line 334, in clean_oldpassword
    if not self.user.check_password(self.cleaned_data.get("oldpassword")):
AttributeError: 'NoneType' object has no attribute 'check_password'
因此,在调试之后,我检查了allauth forms.py中ChangePasswordForm类下clean_Old Password validation method中的
self.user
的值。py正在打印
None
,所以我实际上遇到了上述错误

为什么在使用django allauth ChangePasswordForm时,用户实际上没有


使用
ChangePasswordForm表单时我是否做错了什么?

您需要将用户对象传递给您的类:

form = ChangePasswordForm(data=request.POST, user=request.user)