from rest_framework.permissions import IsAuthenticated
class MyView(APIView):
permission_classes = [IsAuthenticated]
has_permission
method. from rest_framework.permissions import BasePermission
class HasPermission(BasePermission):
permission_name = 'myapp.view_mymodel'
def has_permission(self, request, view):
return request.user.has_perm(self.permission_name)
class MyView(APIView):
permission_classes = [HasPermission]
TokenAuthentication
and BasicAuthentication
, among others.from rest_framework.authentication import TokenAuthentication
class MyView(APIView):
authentication_classes = [TokenAuthentication]
class MyView(APIView):
authentication_classes = [TokenAuthentication]
permission_classes = [HasPermission]