0👍
Get the email and password using form
email = form.cleaned_data['email']
password = form.cleaned_data['password']
If the given email matches with exiting record.
try:
user = User.objects.get(email=email)
if user.check_password(password):
username = user.username
user = authenticate(username=username, password=password)
login(request, user)
messages.success(request, "Welcome {}".format(email))
else:
messages.error(request, "Password not match for {}".format(email))
except User.DoesNotExist:
pass
- [Answer]-Python. Django1.7 DoesNotExist. Matching query does not exist
- [Answer]-Django: if model has related models (ForeignKey) display Fields in main modelform
- [Answer]-Many to Many and Foreign Key relations in django admin
Source:stackexchange.com