0
  • パイソン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))
4

2 に答える 2

2

私は間違っているかもしれませんが、そうではないでしょうか?

usr = authenticate(username=usrnym,password=psswrd)

于 2013-03-21T20:22:51.153 に答える
2

ユーザーではなくユーザー名である必要がありますその構文エラー

usr = authenticate(username = usrnym, password = psswrd)
于 2013-03-21T20:23:33.063 に答える