• django 认证Users


    认证Users:
    
    authenticate(**credentials)[source]
    
    请使用authenticate(),认证一组给定的用户名和密码。
    
    它接收关键字参数形式的凭证,使用默认配置参数是username和password,
    
    如果密码能够匹配给定的用户名,它将返回一个User 对象。
    
    如果密码无效,authenticate()返回None。例子:
    
    
    
    
    def main(req):
        # Do something for anonymous users.
        from django.contrib.auth import authenticate, login
        username=req.POST['username']
        password = req.POST['password']
        user = authenticate(username=username, password=password)
        print '1111111111111111111111111111111'
        print user
        print type(user)
        print '1111111111111111111111111111111'
    
    
    
    
    成功登陆:
    
    
    1111111111111111111111111111111
    admin
    <class 'django.contrib.auth.models.User'>
    1111111111111111111111111111111
    
    
    
    密码错误:
    
    1111111111111111111111111111111
    None
    <type 'NoneType'>
    1111111111111111111111111111111
    
    
    
    正常登陆:
    if user.is_active:
                print '--------user.is_active----------------'
                print user.is_active
                print '--------user.is_active----------------'
    			
    			
    --------user.is_active----------------
    True
    --------user.is_active----------------
  • 相关阅读:
    基本HAL库操作函数整理
    oled(iic协议)
    Uart串口中断收发
    博主回来啦
    博主的冒泡1
    AFO

    起床困难综合症
    费解的开关
    数独
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13348990.html
Copyright © 2020-2023  润新知