Py学习  »  问与答

django 用户认证问题

278565575 • 10 年前 • 3542 次点击  

真心求大神们百忙之中抽出点时间来帮下忙~~留QQ我加您!!

def login_(request):)<br>
    username = request.POST.get('username', '')<br>
    password = request.POST.get('password', ''))<br>
    user = auth.authenticate(username=username, password=password)
    if user is not None and user.is_active:)<br>
        # Correct password, and the user is marked "active")<br>
        auth.login(request,user))<br>
        print user.is_authenticated)<br>
        print request.user)<br>
        # Redirect to a success page.)<br>
        return HttpResponseRedirect("/index/"))<br>
    else:)<br>
        # Show an error page)<br>
        return HttpResponseRedirect("/denglu/"))<br>

登陆成功后跳转到index页面 request.user.is_authenticated 没有值~~提示登陆失败<br>

{% if request.user.is_authenticated %<br>
  <p>Welcome, {{ request.user.username }}. Thanks for logging in.</p><br>
{% else %}<br>
  <p>Welcome, new user. Please log in.</p><br>
{% endif %}<br>
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/312
 
3542 次点击  
文章 [ 1 ]  |  最新文章 10 年前