- auth系统有三个主表主要是,user Group Permission 分别是用户表 和群组表和权限表
从auth系统中导入表
from django.contrib.auth.models import User, Group, Permission
from django.contrib.auth.decorators import permission_required
from django.utils.decorators import method_decorator
- 对视图函数index()上面写上权限控制的装饰如果用户如果对应的用户具有进入视图修改数据库的权限,如果没有权限则进入视图文件配置的路由
@permission_required('app01.add_PerModel')
def index(request):
user = request.POST.get('user')
per = PerModel(user=user)
pei.save()
return HttpReponse('有权限')
setting配置的权限路由
LOGIN_URL = '/form_session/login1/'
def per_add(reqeust):
user = User.objects.filter(username='xiaowang').first()
per = Permission.objects.filter(codename='change_Permodel').first()
user.user_Permissions.add(per)
return HttpResponse('添加成功')
|