I'm trying to make a custom authentication where I login only with the e-mail address without password. I searched over internet but I don't find a good answer. I'm new in Django maybe this is the reason for why I can't find a solution. Can anyone help me to solve this problem? Thanks
Django django.contrib.auth
has authenticate
, login
methods. If you just want login the user using only email
, then get the User
object using email and call login
method
Example
from django.contrib.auth import authenticate, login as auth_login
if request.method == 'POST':
form = SomeLoginForm(request.POST or None)
if form.is_valid():
username = User.objects.get(email=form.cleaned_data['email'])
if user:
auth_login(request, user)
But I don't recommend it. You should validate user using mechanism like password or OTP that's where authenticate
method comes
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.