I have two REST application in my Django project:
api
- should beAllowAny
andReadOnly
!apicrm
- should berest_framework.permissions.IsAuthenticated
How to set this permission for whole app in Django Rest Framework?
I have two REST application in my Django project:
api
- should be AllowAny
and ReadOnly
!apicrm
- should be rest_framework.permissions.IsAuthenticated
How to set this permission for whole app in Django Rest Framework?
Make local confi like:
api
class apiView(viewsets.ModelViewSet) .... {
permission_classes = ()
authentication_classes = ()
}
apicrm
class apiView(viewsets.ModelViewSet) .... {
permission_classes = (IsAuthenticated)
authentication_classes = (JSONWebTokenAuthentication,)
}
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