0

I have two REST application in my Django project:

  1. api - should be AllowAny and ReadOnly!
  2. apicrm - should be rest_framework.permissions.IsAuthenticated

How to set this permission for whole app in Django Rest Framework?

yestema
  • 6,932
  • 4
  • 23
  • 29

2 Answers2

0

Make local confi like:

api

class apiView(viewsets.ModelViewSet) .... {
  permission_classes = ()
  authentication_classes = ()
}

apicrm

class apiView(viewsets.ModelViewSet) .... {
  permission_classes = (IsAuthenticated)
  authentication_classes = (JSONWebTokenAuthentication,)
}
mcmartin
  • 106
  • 3
0

I don't think there is any global settings to define permissions for apps. What I can think here is to make a base view class with the appropriate permissions classes.

Example:

api app

class BaseApiViewSet(viewsets.ModelViewSet):
    permission_classes = (AllowAny, )

# inherit BaseApiViewSet in all other viewsets
class ViewSet1(BaseApiViewSet):
    # code as it is

apicrm app

class BaseApiCrmViewSet(viewsets.ModelViewSet):
    permission_classes = (IsAuthenticated, )

# similary, inherit from BaseApiCrmViewSet in all other viewsets
Sachin
  • 3,576
  • 1
  • 15
  • 24