【发布时间】:2022-01-31 09:25:26
【问题描述】:
当登录详细信息正确填写时,我正在尝试在 Django 中创建登录页面,它重定向到某个页面我面临的问题是,当我输入错误的用户名或密码时,Django 将它们验证为正确并将其重定向到另一个页面我的登录代码如下
def loginpage(request):
if request.method=='POST':
use=request.POST.get('username')
pas=request.POST.get('password')
user=authenticate(request,username=use,password=pas)
if user is not NONE:
login(request,user)
return redirect('data')
else:
messages.info(request,'Username or Password is incorrect')
return render(request,'login.html')
即使在输入数据库中甚至不存在的用户名之后,Django 也验证为正确并且没有显示我期望的错误
【问题讨论】:
-
出于好奇,您为什么将
request作为第一个参数传递给authenticate()函数?该参数默认设置为无。
标签: html python-3.x django authentication django-views