运维开发笔记整理-创建django用户
作者:尹正杰
版权声明:原创作品,谢绝转载!否则将追究法律责任。
一.创建普通用户
C:\Users\yinzhengjie\softwares\PycharmProject\DevOps>python manage.py shell
Python 3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 08:06:12) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>>
>>>
>>> from django.contrib.auth.models import User
>>>
>>> user = User.objects.create_user("yinzhengjie", "yinzhengjie@yinzhengjie.org.cn", "")
>>>
二.创建管理员
C:\Users\yinzhengjie\softwares\PycharmProject\DevOps>python manage.py createsuperuser
Username: admin
Email address: admin@yinzhengjie.org.cn
Password:
Password (again):
Superuser created successfully. C:\Users\yinzhengjie\softwares\PycharmProject\DevOps>
C:\Users\yinzhengjie\softwares\PycharmProject\DevOps>
三.修改用户名的密码
1>.在数据库中查看刚刚创建的2个用户信息
mysql> select * from auth_user\G
2>.进入Django自带的shell环境修改密码
C:\Users\yinzhengjie\softwares\PycharmProject\DevOps>python manage.py shell
Python 3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 08:06:12) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from django.contrib.auth.models import User
>>>
>>>
>>> u = User.objects.get(username='yinzhengjie')
>>>
>>> u.set_password('')
>>>
>>> u.save()
>>>
>>>