djangoguardian权限控制测试-创新互联
导入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是对于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]:
测试user是对于host实例否有 operate_host
In [34]: user.has_perm('operate_host',host)
Out[34]: True
In [36]: assign('use_scripts',user,script)
Out[36]:
网站栏目:djangoguardian权限控制测试-创新互联
当前URL:http://kswjz.com/article/cedipi.html
扫二维码与项目经理沟通
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流