关于我们

质量为本、客户为根、勇于拼搏、务实创新

< 返回

djangoguardian权限控制测试

发布时间:2022-07-27 13:56:24
导入model

In [1]: from guardian.shortcuts import *
In [2]: from resources.models import *
In [3]: from django.contrib.auth.models import *
获取id为2 的 user
In [4]: user = User.objects.get(id=2)

In [24]: host = Host.objects.get(id=1)
In [25]: script = Script.objects.get(id=2)

注销权限:

In [28]: remove_perm('operate_host',user,host)

In [30]: user = User.objects.get(id =2)

Out[31]: <User: zhangfan>

测试user是对于host实例否有 operate_host
In [32]: user.has_perm('operate_host',host)
Out[32]: False

注册user用户 对于host实例的operate权限
In [33]: assign('operate_host',user,host)
Out[33]: <UserObjectPermission: 测试172 | zhangfan | operate_host>

测试user是对于host实例否有 operate_host
In [34]: user.has_perm('operate_host',host)
Out[34]: True


In [36]: assign('use_scripts',user,script)
Out[36]: <UserObjectPermission: get_jps | zhangfan | use_scripts>

djangoguardian权限
控制测试

/template/Home/Dawn/PC/Static

选择风纳云,也许是您成就一番大事业的开端

注册账号