if user is not None:
login(request, user)
return redirect('home')
else:
error_message = "Invalid username or password."
return render(request, 'login.html', {'error_message': error_message})
Using the above code, if user enters wrong credentials, login.html shows up successfully with error message.
But now the URL is http://localhost:8000/authentication_view/.
Now if the user re-enters credentials, the URL will be
http://localhost:8000/authentication_view/authentication_view/,
and it creates Page Not Found error.
If I use return redirect('login_view'), then the error message will not show.
Could someone help me how to show login page with error message without adding Authentication View to the URL?
I was expecting: if user provides wrong credentials, he gets error message and goes back to login page. Now he can re-enter credentials. But now login page is not usable because authentication view name is already added to the URL. New login attempt will add authentication view name twice the URL.
Khawar Pasha is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.