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

1.8k Views Asked by At

Django version 1.10.7

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

Importing the authenticate() like this:
from django.contrib.auth import authenticate, login

Calling authenticate() like this :
authenticate(request, username=request.POST['username'] ,password=request.POST['password'])

3

There are 3 best solutions below

3
chicocvenancio On BEST ANSWER

In 1.10 authenticate does not take positional arguments (docs) call it as

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

Set the authenticate to a variable and don't pass in request, such as:

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

3
aspo On

Use authenticate without the request, only takes username and password authenticate(username=XXX,password=XXX). See the documentation https://docs.djangoproject.com/en/1.11/_modules/django/contrib/auth/#authenticate