[Python] ModelViewSet does not overwrite DEFAULT_PERMISSION_CLASSES'

Discussão em 'Python' iniciado por Stack, Maio 27, 2025.

  1. Stack

    Stack Membro Participativo

    Hello I'm working on making all urls requires user to be authenticate , but some urls i want them to be accessible by public, so i use permission_classes = [AllowAny] and authentication_classes = ([]) to overwrite default configurations it work in APIVIEW but not in viewsets.ModelViewSet why ?

    settings.py

    REST_FRAMEWORK = {
    'DEFAULT_PERMISSION_CLASSES': [
    'rest_framework.permissions.IsAuthenticated',
    ],
    'DEFAULT_FILTER_BACKENDS': [
    'django_filters.rest_framework.DjangoFilterBackend',
    ],
    'DEFAULT_AUTHENTICATION_CLASSES': [
    'rest_framework_simplejwt.authentication.JWTAuthentication',
    ],
    'DATETIME_FORMAT': "%Y-%m-%d %H:%M:%S",
    }



    views.py

    class ToolsListViewSet(viewsets.ModelViewSet):
    serializer_class = ToolsListSerializer
    permission_classes = [AllowAny]
    authentication_classes = ([])
    pagination_class = None
    def get_queryset(self):
    return Tools.objects.filter(is_active=True)
    enter code here



    error

    {
    "detail": "Authentication credentials were not provided."
    }

    Continue reading...

Compartilhe esta Página