Is there any way I can use email as user name with out specifying custom user model. I am new to django, From past few hour I am searching and trying to find a way. I try creating custom modal but then everything get changed like admin login.
Secondly is there any way to define a custom model for specific app. eg. fronted only. So that back-end stay as is.
I just need to use email as username for users login.
Is it possible to use
USERNAME_FIELD = 'email'
我实际上最终使用了django-authtools
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.