login() missing 1 required positional argument: 'user'

12,300

You're not using the right view, try this instead

path('login',views.login_view, name = 'login ')
Share:
12,300

Related videos on Youtube

AJAY RAWAT
Author by

AJAY RAWAT

Updated on June 04, 2022

Comments

  • AJAY RAWAT
    AJAY RAWAT about 2 years

    Here is my view,

    def login_view(request) :
        if request.method == 'POST':
            form = LoginForm(request.POST)
            if form.is_valid():
              email = form.cleaned_data['email']
              password = form.cleaned_data['password']
              user = authenticate(email=email, password=password)
    
              if user is not None:
                  form = LoginForm()
                  login(request, user)
    

    I get an error:

    login() missing 1 required positional argument: 'user'
    

    Also, I am using a custom user model

    My urls.py:

    urlpatterns = [
    path('',views.register, name='register' ),
    path('form',views.form, name = 'form'),
    path('login',views.login, name = 'login ')]
    
    • scharette
      scharette almost 6 years
      Can we see your urls.py
    • AJAY RAWAT
      AJAY RAWAT almost 6 years
      Sure . I’ll add it
    • AJAY RAWAT
      AJAY RAWAT almost 6 years
      @scharette Please suggest a solution, thanks : )
    • Willem Van Onsem
      Willem Van Onsem almost 6 years
      You probably overwrote login somewhere with another function.
  • AJAY RAWAT
    AJAY RAWAT almost 6 years
    Thank you very much
  • AJAY RAWAT
    AJAY RAWAT almost 6 years
    I forgot to change that. My bad 😅. It is running smoothly now. Thanks :)
  • scharette
    scharette almost 6 years
    This answer is confusing. Could you give OP more insights on what is the purpose of your solution ?
  • AJAY RAWAT
    AJAY RAWAT almost 6 years
    You are correct. The error was in the urls. Thanks :)
  • Sam
    Sam almost 6 years
    oh my bad. Did not notice that.