I'm seeking to understand how the ViewSet compliments URL routing when used with routers in the context of Django REST framework. When I'm requesting a collection at api/v2/people/, a 404 response is returned. I'm not clear on what else is required for the view to render in the browser and get a 200 status code as a part of the response?
urls.py
from django.urls import path, include
from rest_framework import routers
from people import views
router = routers.SimpleRouter()
router.register(r'people', views.PersonViewSet, basename="people")
urlpatterns = [
path('admin/', admin.site.urls),
path('api-path/', include('rest_framework.urls')),
path('api/v2/people/', include(router.urls), name="people")
]
people/views.py
from rest_framework.viewsets import ViewSet
from .models import Person
from .serializers import PersonSerializer
class PersonViewSet(ViewSet):
def list(self, request):
queryset = Person.objects.all()
serializer = PersonSerializer(queryset, many=True)
return Response(serializer.data)
