位置
APIView---->dispatch方法---->initial方法--->self.check_permissions(request)(APIView的对象方法)
分析
def check_permissions(self, request):
"""
Check if the request should be permitted.
Raises an appropriate exception if the request is not permitted.
"""
# 这里self.get_permissions和认证源码一样,结果也为权限的列表对象
# permission为一个个自定义的权限类的对象
for permission in self.get_permissions():
# 自定义的权限类必须要有一个has_permission方法
# has_permission方法参数:权限对象self、request请求对象、视图类对象self
# 该方法的返回值:有权限返回true,无返回false
if not permission.has_permission(request, self):
self.permission_denied(
request,
message=getattr(permission, 'message', None),
code=getattr(permission, 'code', None)
)
标签:permission,self,request,rest,framework,源码,权限,permissions
From: https://www.cnblogs.com/suncolor/p/16826441.html