zoukankan      html  css  js  c++  java
  • django orm创建用户

    Django 从开始就带有一个用户认证系统,它处理用户账号,组,权限以及基于cookie的永不会话
    
    Python 2.7.3 (default, Mar 30 2017, 20:15:12) 
    [GCC 4.4.7 20120313 (Red Hat 4.4.7-17)] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import os,django
    >>> os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")
    'mysite.settings'
    >>> django.setup()
    aaaaaaaaaaaaaaaa
    >>> from django.contrib.auth.models import User
    >>> 
    
    allnavi = User.objects.all()
    
    user = User.objects.create_user('john', 'lennon@thebeatles.com', 'johnpassword')
    
    user.save()
    
    mysql> mysql> select * from auth_user;
    +----+-------------------------------------------------------------------------------+------------+--------------+----------+------------+-----------+-----------------------+----------+-----------+----------------------------+
    | id | password                                                                      | last_login | is_superuser | username | first_name | last_name | email                 | is_staff | is_active | date_joined                |
    +----+-------------------------------------------------------------------------------+------------+--------------+----------+------------+-----------+-----------------------+----------+-----------+----------------------------+
    |  1 | pbkdf2_sha256$36000$u7kGbss2PJyJ$bJHqxcp4vXdNMpL5DgwEtFlmW6p7Oo/KA58LOHRLMnE= | NULL       |            0 | john     |            | Lennon    | lennon@thebeatles.com |        0 |         1 | 2018-09-13 16:01:20.731633 |
    +----+-------------------------------------------------------------------------------+------------+--------------+----------+------------+-----------+-----------------------+----------+-----------+----------------------------+
    1 row in set (0.00 sec)
    
    >>> allnavi = User.objects.all()
    >>> print allnavi
    <QuerySet [<User: john>]>
    >>> 
    
    user = User.objects.create_user('xxxx', 'lennon@thebeatles.com', 'johnpassword')
    
    
  • 相关阅读:
    LeetCode-Merge Intervals
    LeetCode-Longest Valid Parentheses
    LeetCode-Divide Two Integers
    LeetCode-Next Permutation
    LeetCode-Jump Game II
    LeetCode-Maximal Rectangle
    BZOJ 1230: [Usaco2008 Nov]lites 开关灯
    BZOJ 2839: 集合计数
    BZOJ 3211: 花神游历各国
    BZOJ 5334: [Tjoi2018]数学计算
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13349043.html
Copyright © 2011-2022 走看看