我们从Python开源项目中,提取了以下5个代码示例,用于说明如何使用rest_framework.permissions.IsAdminUser()。
def get_permissions(self): """Define custom permissions for different methods""" # at minimum require users to be authenticated self.permission_classes = [IsAuthenticated] # for PUT requests require users to be admins if self.request.method == 'PUT': self.permission_classes.append(IsAdminUser) return super(viewsets.ViewSet, self).get_permissions()
def has_permission(self, request, view): if request.method in SAFE_METHODS: return True return IsAdminUser().has_permission(request, view)
def has_permission(self, request, view): if request.method == 'POST': return True return IsAdminUser().has_permission(request, view)
def get_staff_api_permissions(): """get public api permissions""" return [permissions.IsAdminUser]