Standard authorization from the Django documentation, but an error occurs in the line calling the login () function

Exception Type: TypeError Exception Value: 'str' object is not callable 

view.py:

 from django.contrib.auth import authenticate, login, logout def auth(request): login = request.POST.get("login", "") password = request.POST.get("password", "") user = authenticate(username=login, password=password) if user is not None: if user.is_active: login(request, user) return redirect('/') else: # Return a 'disabled account' error message print('disabled account') else: # Return an 'invalid login' error message. print('invalid login') 

The authenticate () function works fine, the user is. Please tell me what could be the problem?

    1 answer 1

    Your login is a string that is installed here:

     login = request.POST.get("login", "") 

    A string cannot be called as a function. And the login function, which you imported at the beginning of the file, became inaccessible, because instead of it you created the login string variable in this very line.

    Rename your login line to, for example, username , and everything will be fine