python django 权限认证相关
- 权限
CLICK ME
Group功能
# 测试auth模块的Group功能
from django.contrib.auth.models import Group
Group.objects.get_or_create(name='user_group')
user_group = Group.objects.get(name='user_group')
# assign_perm('view_project', user_group) #需要加上app
assign_perm('app.view_project', user_group)
user = authenticate(username='test', password='test')
user.groups.add(user_group)
# 查看get_objects_for_user方法
from guardian.shortcuts import get_objects_for_user
user = authenticate(username='test', password='test')
ret1 = get_objects_for_user(user,'app.view_project')
ret3 = get_objects_for_user(user,'app.view_project').first()
# print(ret2)
# print(ret3)
- 重写User模型和登录验证
- things
CLICK ME
title