简体   繁体   English

Django TypeError:authenticate()恰好接受0个参数(给定3个)

[英]Django TypeError: authenticate() takes exactly 0 arguments (3 given)

Django version 1.10.7

I'm getting TypeError: authenticate() takes exactly 0 arguments (3 given) 我收到TypeError: authenticate() takes exactly 0 arguments (3 given)

Importing the authenticate() like this: 像这样导入authenticate():
from django.contrib.auth import authenticate, login

Calling authenticate() like this : 像这样调用authenticate():
authenticate(request, username=request.POST['username'] ,password=request.POST['password'])

Set the authenticate to a variable and don't pass in request, such as: 将authenticate设置为变量,并且不传递请求,例如:

auth = authenticate(username=request.POST['username'] ,password=request.POST['password'])

And then use login to get the user logged in: 然后使用登录名使用户登录:

login(request, auth)

Don't forget to import login 不要忘记导入登录名

在1.10版本中, authenticate不接受位置参数( docs )称为

authenticate(username=request.POST['username'], password=request.POST['password'])

Use authenticate without the request, only takes username and password authenticate(username=XXX,password=XXX) . 在不请求的情况下使用身份验证,仅使用用户名和密码进行authenticate(username=XXX,password=XXX) See the documentation https://docs.djangoproject.com/en/1.11/_modules/django/contrib/auth/#authenticate 请参阅文档https://docs.djangoproject.com/zh-CN/1.11/_modules/django/contrib/auth/#authenticate

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM