1.总览
包括:
- user:
- permissions:二进制的标志,标明是否有权限执行某操作
- groups:给多个用户打标签和设置权限
2.安装&激活
authentication的支持是作为一个django application,绑定在django.contrib.auth模块中。安装步骤:
- 在settings.py中的INSTALLED_APPS中,添加django.contrib.auth和django.contrib.contenttypes。
- run: manage.py syncdb
3.类Class
(1)User
class models.User
Fields
- username:required
- first_name:optional
- last_name:
- email:
- password:
- is_staff:
- is_active:
- is_superuser:
- last_login:
- date_joined:
Methods
- is_anonymous():
- is_authenticated():
- get_full_name():
- set_password():
- check_password():
- set_unusable_password():
- has_usable_password():
- get_group_permissions():
- get_all_permissions():
- has_perm():
- has_perms():
- has_module_perms():
- email_user():
- get_profile():
(2)UserManager
class models.UserManager
Methods
- create_user():
- make_random_password():
(3)AnonymousUser
class models.AnonymousUser
4.基本用法
(1)创建用户
(2)修改密码
(3)创建超级用户
(4)存储用户的附加信息profile
- 创建自定义类:必须定义一个field去关联User,再定义附加的field:
- 在settings.py中增加配置:
- 获取profile:get_profile()