Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/22.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-authenticate()返回None_Python_Django_Authentication_Nonetype - Fatal编程技术网

Python Django-authenticate()返回None

Python Django-authenticate()返回None,python,django,authentication,nonetype,Python,Django,Authentication,Nonetype,我读了很多关于这个问题的文章,问题总是存在的。当我提交登录表单时,authenticate函数返回None。我使用函数set_password进行注册,它不会改变任何内容 以下是我的代码: 您的问题是,您试图根据电子邮件/密码对对用户进行身份验证,但没有后端接受这样的一对。型号后端接受用户名/密码对,因此要使用电子邮件进行身份验证: (...) if form.is_valid(): email = form.cleaned_data["email"] password = fo

我读了很多关于这个问题的文章,问题总是存在的。当我提交登录表单时,authenticate函数返回None。我使用函数set_password进行注册,它不会改变任何内容

以下是我的代码:


您的问题是,您试图根据电子邮件/密码对对用户进行身份验证,但没有后端接受这样的一对。型号后端接受用户名/密码对,因此要使用电子邮件进行身份验证:

(...)
if form.is_valid():
    email = form.cleaned_data["email"]
    password = form.cleaned_data["password"]
    username = User.objects.get(email=email).username
    user = auth.authenticate(username=username, password=password)
    if user:
(...)

您的问题是,您试图根据电子邮件/密码对对用户进行身份验证,但没有后端接受这样的一对。型号后端接受用户名/密码对,因此要使用电子邮件进行身份验证:

(...)
if form.is_valid():
    email = form.cleaned_data["email"]
    password = form.cleaned_data["password"]
    username = User.objects.get(email=email).username
    user = auth.authenticate(username=username, password=password)
    if user:
(...)