- パイソン3
- ジャンゴ1.5
でユーザーの作成に成功し、ユーザーcreate_user()
は管理セクションにログインできます。しかし、ユーザーが他の場所にログインできるように、views.py でコードを作成しても機能しません。これが私が使用しているコードです。ユーザー名とパスワードが間違いなく正しい場合authenticate()
でも、 None
.
def dologin(request):
usrnym = request.POST['usrnym']
psswrd = request.POST['usrpass']
usr = authenticate(user=usrnym,password=psswrd)
if usr is not None:
if usr.is_active:
login(request, usr)
# redirect to success page
else:
pass
# redirect to a 'disabled account' error message
else:
# return an 'invalid login' error message
errmsg = "Invalid login. Password and username did not match."
template = loader.get_template('fsr/loginform.html')
context = RequestContext(request, {
'title': "Login Page",
'error': errmsg,
'usr': usrnym,
'pwd': psswrd,
'usra': usr,
})
return HttpResponse(template.render(context))