能够在我的注册视图中成功注册用户,但是当我尝试使用user_login视图中的这些凭据登录时,我被重定向到一个说明我的凭据错误的页面。问题是什么?这是代码。
user_login视图
def user_login(request):
if request.method == 'POST':
username = request.POST.get('username','')
password = request.POST.get('password','')
user = authenticate(username=username, password=password)
if user is not None:
if user.is_active:
.
login(request, user)
return HttpResponseRedirect('/rango/')
else:
return HttpResponse("your acc was disabled")
else:
print "Invalid login details: {0}, {1}".format(username, password)
return HttpResponse('Invalid login details')
else:
return render(request,'login.html', {})
登录模板 兰戈
<body>
<h1>Login to Rango</h1>
<form id = "login_form" method = "post" action = "/rango/login/">
{% csrf_token %}
Username: <input type = "text" name = "username" value="" size="50"/>
<br/>
Password: <input type = "password" name = "username" value="" size="50"/>
<br/>
<input type = "submit" value = "submit"/>
</form>
</body>
答案 0 :(得分:0)
您的密码输入名称错误。它应该是:
Password: <input type = "password" name = "password" value="" size="50"/>