User not Authenticating.

39 views
Skip to first unread message

Lawal Tobiloba Samuel

unread,
Apr 24, 2023, 12:26:57 PM4/24/23
to django...@googlegroups.com
Hi devs, 
I wrote code for user authentication and login but I am not quite sure of it. On the web interface it keeps displaying username or password incorrect (message set in views.py).

login error img.jpg
login error.jpg

Lawal Tobiloba Samuel

unread,
Apr 24, 2023, 12:28:57 PM4/24/23
to django...@googlegroups.com
code here:

def loginPage(request):
    if request.method == "POST":
        username = request.POST.get("username")
        password = request.POST.get("password")
        userLogin = authenticate(username=username, password=password)
        if userLogin is not None:
            login(request, userLogin)
            return redirect("home")
        else:
            messages.info(request, "Username or Password incorrect.")
    context = {"title": "User Login"}
    return render(request, "account/login.html", context)




 







 

Lawal Tobiloba Samuel

Computer Engineer

Front-end Developer

IT Support Specialist

 

Mobile:     +23480-6386-0181

                  +23481-2027-2000

Email:        oluwash...@gmail.com

                  Lawalt...@yahoo.com

 

 

 


Opeoluwa Fatunmbi

unread,
Apr 24, 2023, 12:30:34 PM4/24/23
to django...@googlegroups.com

Let me see your login.html






--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAAscozW9b%2B-RBrnBtNJMMdz5w%3DOStYRuW1mf35kaTBBva%2Br6Lg%40mail.gmail.com.

oluwafemi damilola

unread,
Apr 24, 2023, 12:51:45 PM4/24/23
to django...@googlegroups.com
userLogin = authenticate(request, username=username, password=password)

Ruby Shell

unread,
Apr 24, 2023, 2:12:10 PM4/24/23
to Django users
`authenticate` requires a positional argument (request)
try  userLogin = authenticate(request, username=username, password=password)

Lawal Tobiloba Samuel

unread,
Apr 24, 2023, 3:27:14 PM4/24/23
to django...@googlegroups.com
I later got what I did wrong...

I wanted to retrieve the user information from the form (request.POST.get("username")), but in d form there was no input tag that is named username nor password...

So when the view function request those informations, it was returning an empty string that was why it did not authenticate.

I just had to add the name parameter in the input tag of login.html

Reply all
Reply to author
Forward
0 new messages