July 2018
Intermediate to advanced
324 pages
8h 14m
English
Django REST Framework provides a router module to configure the standard URL configurations. It automatically adds support for all required URLs related to the mentioned viewsets. Read more about the routers here: http://www.django-rest-framework.org/api-guide/routers/. The following is the code snippet related to our route configuration.
File—gallery/urls.py:
from django.urls import path, includefrom rest_framework import routersfrom gallery.views import PhotoAlbumViewset, PhotoViewsetrouter = routers.DefaultRouter()router.register('albums', PhotoAlbumViewset)router.register('albums/(?P<album_id>[0-9]+)/photos', PhotoViewset)urlpatterns = [ path(r'', include(router.urls)),]
Here, we created a default router and ...
Read now
Unlock full access