django rest框架的复杂权限流
rest_condition的Python项目详细描述
rest条件
==
django rest framework的复杂权限流。
installation
----
安装最新版本的最简单方法是使用
pip/easy\\u install将其从pypi中拉出来:
:
从github存储库并手动安装它:
:
python setup.py install
example
----
代码::python
from rest_framework.response import response
from rest_framework.views import apiview
from rest_framework.permissions import basepermission
from rest_condition import conditionalpermission,c,and,or,not
您的权限检查此处
返回true
Class Perm2(BasePermission):
您的权限检查此处
返回false
perm2)与:c(perm1)相同;perm2
expr2=和(perm1,perm2)与:c(perm1)和perm2
expr3=不(perm1)相同;与:~c(perm1)
expr4=和(不(perm1)和(不(perm1)或(perm1,不(perm2))相同;与:~c(perm1)和(c(perm1)相同;与:~c(perm1)&;与:~c(perm1)和(perm1)~c(perm2)~c(perm2))
;在api视图中使用表达式
类示例视图(apiview):
权限类=[或(和(perm1,perm2),而不是(perm2)),]
或简单:
权限类=[c(perm1)&perm2~c(perm2),]
def get(self,request,格式=无):
content={'status':'允许请求'}
返回响应(content)
class otherexampleview(exampleview):
&;~c(perm2))
许可证
----
_ django-rest-framework:http://django-rest-framework.org/
。马克西姆卡门科夫:HTTPS://Github. COM/CAXAP/
==
django rest framework的复杂权限流。
installation
----
安装最新版本的最简单方法是使用
pip/easy\\u install将其从pypi中拉出来:
:
从github存储库并手动安装它:
:
example
----
代码::python
from rest_framework.response import response
from rest_framework.views import apiview
from rest_framework.permissions import basepermission
from rest_condition import conditionalpermission,c,and,or,not
返回true
Class Perm2(BasePermission):
返回false
perm2)与:c(perm1)相同;perm2
expr2=和(perm1,perm2)与:c(perm1)和perm2
expr3=不(perm1)相同;与:~c(perm1)
expr4=和(不(perm1)和(不(perm1)或(perm1,不(perm2))相同;与:~c(perm1)和(c(perm1)相同;与:~c(perm1)&;与:~c(perm1)和(perm1)~c(perm2)~c(perm2))
;在api视图中使用表达式
类示例视图(apiview):
权限类=[或(和(perm1,perm2),而不是(perm2)),]
或简单:
权限类=[c(perm1)&perm2~c(perm2),]
def get(self,request,格式=无):
content={'status':'允许请求'}
返回响应(content)
class otherexampleview(exampleview):
&;~c(perm2))
许可证
----
_ django-rest-framework:http://django-rest-framework.org/
。马克西姆卡门科夫:HTTPS://Github. COM/CAXAP/