I am using Django Rest Framework for my API service. In my settings.py I've got following REST_FRAMEWORK setting:
REST_FRAMEWORK = {
...
'DEFAULT_PERMISSION_CLASSES': (
'rest_framework.permissions.IsAuthenticated'
)
...
}
Now I want to change permission classes to allow anyone to use one view. I had used @permission_classes decorator.
class UserViewSet(viewsets.ModelViewSet):
serializer_class = RegisterSerializer
queryset = User.objects.all()
@permission_classes([permissions.AllowAny,])
def create(self, request, *args, **kwargs):
data = request.data
...
I should be able to perform create action without any permissions. Instead I receive Authentication error when try to access the API.
"detail": "Authentication credentials were not provided."
According to docs @permission_classes decorator is correct way for such permission overriding. This is Django 2.2.4 and DRF 3.10.2.
EDIT
I forgot to mention that I do not want to allow any one to access any view, only the chosen one. Most of views should have IsAuthenticated permission which is set globally.