From documentation about django.contrib.auth.authenticate
function, we find -
Use authenticate() to verify a set of credentials. It takes credentials as keyword arguments, username and password for the default case, checks them against each authentication backend, and returns a User object if the credentials are valid for a backend.
Now, my question is what do they mean by username?
- Is it the name of the column of a model?
- Or is it a primary key to a model?
Actually, I have been sending email as a username because I wanted to check credentials based on email (primary key) rather than username (whatever it means) but it didn't work... But I named one of a column of my model to username but it still didn't work... So, I wonder what do they mean by username exactly.
My code that didn't work -
email = request.POST['email']
#email = request.POST['username'] Changed email column-name to username but didn't work!
password = request.POST['password']
user = authenticate(request, username=email, password=password)
print (user) ## None