输入错误的用户名和密码仍然 django 验证它是正确的

Entering wrong username and password still django authenticate it as correct

我正在尝试在 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 也会正确验证并且不会显示我预期的错误

你有大写 NONE 而不是 None。您一定是不小心从 pickle 或其他一些库中导入了 NONE,这就是它进行验证而不是引发错误的原因。检查文件顶部的导入并更改为 if user is not None.