[Django]-Authenticate() got an unexpected keyword argument 'username'

13👍

The code is using authenticate as a view name. That overwrites the reference to the imported function authenticate.

from django.contrib.auth import authenticate, login
#                               ^^^^^^^^^^^^

def authenticate(request):
#   ^^^^^^^^^^^^

Rename the view:

def other_view_name(request):

Or import the function as different name (also change call to the function):

from django.contrib.auth import authenticate as auth
...

user = authenticate(...) -> user = auth(...)

Or import django.contrib.auth and use the fully qualified name.

import django.contrib.auth
...

user = authenticate(...) -> user = django.contrib.auth.authenticate(...)

Leave a comment