Django Serializer - `methodViewSet(viewsets.ViewSet)` is not displayed in url list
I am trying to combine multiple serializers into a single API call, and as a result, I am using viewsets.ViewSet
. I am aware that viewsets.ModelViewSet
automatically generates the routes, but with viewsets.ViewSet
, I am not seeing the expected route for my API.
When I switch to viewsets.ModelViewSet
, the route becomes available. This makes me think my issue is specific to how viewsets.ViewSet
handles routing.
According to the documentation (https://www.django-rest-framework.org/api-guide/viewsets/), I should be able to register the URL like I would with ModelViewSet
. However, the route doesn't appear when using viewsets.ViewSet
.
Any suggestions on what might be going wrong?
views.py
class MethodViewSet(viewsets.ViewSet):
permission_classes = [IsAuthenticated]
authentication_classes = [TokenAuthentication]
@action(detail=False, methods=['get'], url_path='method-path')
def list(self, request):
...
urls.py
from rest_framework.routers import DefaultRouter
from .views import (
MethodViewSet,
)
from rest_framework.authtoken.views import obtain_auth_token
router = DefaultRouter()
...
router.register(r'method-path', MethodViewSet, basename='methodbasename')