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.
    
  • 相关阅读:
    迭代器基础知识
    C语言I博客作业09
    第一周作业
    C语言1博客作业04
    C语言I博客作业08
    C语言博客作业05
    C语言I作业12—学期总结
    C语言I博客作业10
    C语言I博客作业06
    C语言I博客作业11
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13349041.html
Copyright © 2011-2022 走看看