我有一个观点:
class DealsView(APIView):
permission_classes = (IsAuthenticated, IsOwnerOrCuratorOrDirectorOrNotAllowed, )
def get(self, request, user_pk):
...
但是为了正确检查权限,我需要将user_pk url参数传递给权限:
class IsOwnerOrCuratorOrDirectorOrNotAllowed(permissions.BasePermission):
def has_permission(self, request, view):
...
默认情况下,它没有除self,request和view之外的任何参数。我该怎么办呢?
答案 0 :(得分:4)
试试这个:
class IsOwnerOrCuratorOrDirectorOrNotAllowed(permissions.BasePermission):
def has_permission(self, request, view):
user_pk = view.kwargs.get('user_pk', None)
...