rohan_tare
rohan_tare

Reputation: 171

how to apply permission class to particular method in class based views in Django-Rest Framework?

I want to apply permission only for "PUT" method not for "POST"

class Signup(APIView):
    def post(self, request, format=None):
        something...something

    @authentication_classes((ExpiringTokenAuthentication,))
    @permission_classes((IsAuthenticated,))
    def put(self, request, format=None):
        something...something

Upvotes: 3

Views: 1235

Answers (1)

almalki
almalki

Reputation: 4775

Check the HTTP method on your permission class has_permission method and apply your checks if it was PUT:

class ExpiringTokenAuthentication(permissions.BasePermission):

    def has_permission(self, request, view):
        if request.method == 'PUT':
           # do it here


class Signup(APIView):
    permission_classes = (BlacklistPermission,)

Upvotes: 3

Related Questions