DRF Register a sub viewset

Viewed 161

I try to configure a viewset "behind" another one. Here is the code :

from rest_framework import routers
router = routers.DefaultRouter()
router.register('places/nice', NicePlacesViewSet)
router.register('places/nice/current', CurrentNice remove last slash PlacesViewSet)

Both routes are available according to /manage.py show_urls, but if a do a GET on places/nice/current, I just get a 404 error.

And if a change the last line to remove last slash:

router.register('places/nice_current', CurrentPlacesViewSet)

everything work perfectly and I can get current viewset informations.

Is there any limitations on nested viewsets like that ? Viewset should not be nested on the same path ? :)

1 Answers

Change the order of the register() statements as

router = DefaultRouter()
router.register('places/nice/current', CurrentPlacesViewSet)
router.register('places/nice', NicePlacesViewSet)
Related