[Django]-How to set authentication and permission only on PUT requests in django REST in viewsets?

3👍

Override get_permissions method on the ModelViewSet class.

Example:

class FooViewSet(ModelViewSet):
    authentication_classes = (SessionAuthentication, BasicAuthentication, )
    permission_classes = (IsAuthenticated, )

    def get_permissions(self):
        if self.request.method != 'PUT':
            return []
        return super().get_permissions()
👤Sachin

Leave a comment