我在登录视图中收到属性错误。它说'NoneType'对象没有属性'check_password'。
这是我的 view.py :
def login_view(request):
if request.method == "POST":
username = request.POST['username']
password = request.POST['password']
u = User.objects.get(username=username)
if username and password:
user = authenticate(username= username, password= password)
if not user.check_password(password):
return render(request, 'post/login.html', {'error_message': 'Incorrect password'})
if not user:
return render(request, 'post/login.html', {'error_message': 'This user does not exist'})
if not user.is_active:
return render(request, 'post/login.html', {'error_message': 'Your account has been disabled'})
if user.is_active:
login(request, user)
return render(request, 'post/home.html', {'u' : u})
return render(request, 'post/login.html')
任何帮助都将不胜感激。
答案 0 :(得分:0)
可能是因为你的变量是空的。确保您正确发布了您的身份验证变量(用户名和密码)。