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()
python类ViewSet()的实例源码
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()