2👍
There are several issues with your view. I think that the biggest problem is that you have not realised that the urls (e.g. /login/
), views e.g. user_login
, and templates (e.g. templates/smith.html
) are all decoupled.
The template e.g. templates/smith.html
is separate from the url, you would not expect to see it in the url bar.
If you want to redirect the user from /login/
to another url, you should return a redirect response.
from django.http import HttpResponseRedirect
return HttpResponseRedirect('/smith/')
You would then need to add a url pattern for /smith/
to your urls.py
.
Here’s are some more couple of issues with your view:
You have authenticated the username and password, but you have not logged them in. See how to log a user in for more details.
for user in 'username','password':
I’m not sure what you are trying to do here. This code will loop twice. First, with user='username'
, then with user='password'
.
if ('username','password') == ('jsmith1','smithproject'):
This is comparing the string ‘username’ (not the variable) to the string ‘jsmith1’, and the string ‘password’ (not the variable) to the string ‘smithproject’. Therefore it will always return False
. I hope you just have the password ‘smithproject’ hardcoded for testing – in production you should avoid having passwords in your code.