大橙子网站建设,新征程启航

为企业提供网站建设、域名注册、服务器等服务

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权限
控制测试
网页名称:djangoguardian权限控制测试-创新互联
浏览地址:http://dzwzjz.com/article/cedipi.html
在线咨询
服务热线
服务热线:028-86922220
TOP