Django "login() takes exactly 1 argument (2 given)" error

Your view function is also called login, and the call to login(request, user) ends up being interpreted as a attempt to call this function recursively:

def login(request):
    ...
    login(request, user)

To avoid it rename your view function or refer to the login from django.contrib.auth in some different way. You could for example change the import to rename the login function:

from django.contrib.auth import login as auth_login

...
auth_login(request, user)

One possible fix:

from django.contrib import auth

def login(request):
    # ....
    auth.login(request, user)
    # ...

Now your view name doesn't overwrite django's view name.


Another way:

from django.contrib.auth import login as auth_login

then call auth_login(request, user) instead of login(request, user).