0
为什么我不能设法得到我的登录工作..登录与电子邮件的代码错误
views.py
def candidate_login(request):
if request.method == 'POST':
email = request.POST.get('email')
password = request.POST.get('password')
user = authenticate(email=email,password=password)
if user:
if user.is_active & user.check_password(password):
login(request,user)
return HttpResponseRedirect(reverse('index'))
else:
HttpResponse("Account not active, please contact Admin")
else:
print("Someone tried to login and failed")
return HttpResponse("Invalid login detailed supplied!")
else:
return render(request,'candidate_login.html',{})
当我尝试登录我得到的error
消息:无效的登录详细供应!
你能帮我把它工作吗? THK你非常 拉斐尔
models.py
from django.db import models
from django.contrib.auth.models import AbstractUser
# Create your models here.
class MyUser(AbstractUser):
is_hr = models.BooleanField(default=False)
is_candidate = models.BooleanField(default=False)
is_employee = models.BooleanField(default=False)
company = models.CharField(max_length=100, default='')
不是问题,但你不需要调用'user.check_password';这已经在'authenticate'中完成了。无论如何,在Python中是布尔值,只是'和',而不是'&'。 –
电子邮件是否被用作用户名?你有没有使用自定义的'用户'模型? –
嗨Sachin,是的,我使用了一个自定义用户模型!我编辑我的文章哟显示我的model.py。使用电子邮件作为用户名是什么意思? – Ben2pop