3

I have a viewset subclassing from modelviewset, I add next:

authication_classes = [SessionAuthentication,BasicAuthentication]
permission_classes = [IsAuthenticated]

Then, got following message when list, detail/retrieve and put requests.

"detail": "Authentication credentials were not provided."

What should i change to only give this message when I update the data ??

atline
  • 28,355
  • 16
  • 77
  • 113
  • To help you out with your problem - it would be useful that you add the viewset class and also the request which you send to that endpoint to see how do you actually set the authentication credentials. – Enthusiast Martin Oct 07 '18 at 15:55
  • Here is a link to similar question kindly follow the link. https://stackoverflow.com/questions/37642175/how-to-add-django-rest-framework-permissions-on-specific-method-only – ashutosh singh Nov 01 '18 at 09:26
  • https://stackoverflow.com/questions/37642175/how-to-add-django-rest-framework-permissions-on-specific-method-only 1.someone have answered a similar question. – ashutosh singh Nov 01 '18 at 09:27

1 Answers1

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
  • 3,576
  • 1
  • 15
  • 24