我是Django编程的新手,我遇到了这个问题。
这是我在views.py
中的代码:
def login(request):
if request.method == 'POST':
email = request.POST['email']
password = request.POST['password']
else:
context = RequestContext(request, {})
return render(request, 'login.html', context)
如何搜索在html表单中插入电子邮件的用户,并检查密码是否正确?
提前感谢您的帮助。
答案 0 :(得分:0)
试试这个:
def login(request):
if request.method == 'POST':
email = request.POST['email']
password = request.POST['password']
# Assuming the fields in your `User` model are labeled the same
user = authenticate(email=email, password=password)
else:
context = RequestContext(request, {})
return render(request, 'login.html', context)