zoukankan      html  css  js  c++  java
  • django 请求中的认证

    def main(req):
       username=req.POST['username'].encode('raw_unicode_escape')
       print username
       print type(username)
       passwd=req.POST['password']
       print passwd
       from django.contrib.auth import authenticate
       user = authenticate(username=username, password=passwd)
       print user
       if user is not None:
        # the password verified for the user
        if user.is_active:
            print("User is valid, active and authenticated")
            req.user=user
        else:
            print("The password is valid, but the account has been disabled!")
       else:
        # the authentication system was unable to verify the username and password
        print("The username and password were incorrect.") 
       print '------------------------------------------'
       print req.user
       print '------------------------------------------'
       if req.user.is_authenticated():
        # Do something for authenticated users.
          return render_to_response('main.html')
       else:
          return render_to_response('index.html')
        # Do something for anonymous users.
    
  • 相关阅读:
    Pandas索引和选择数据
    Pandas选项和自定义
    Pandas字符串和文本数据
    Pandas排序
    Pandas迭代
    Pandas重建索引
    Pandas函数应用
    Pandas描述性统计
    Pandas基本功能
    nyoj 234 吃土豆
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13349041.html
Copyright © 2011-2022 走看看