Adding a Router
Learn how to create routes in Django and how to send http requests to RESTful API using Insomnia.
We'll cover the following...
Routers allow us to quickly declare all of the common routes for a given controller. The next code snippet shows a viewset to which we will be adding a router.
At the root of the apps project (core
), create a file named routers.py
.
And let’s add the code:
Press + to interact
from rest_framework import routersfrom core.user.viewsets import UserViewSetrouter = routers.SimpleRouter()# ##################################################################### ## ################### USER ###################### ## ##################################################################### #router.register(r'user', UserViewSet, basename='user')urlpatterns = [*router.urls,]
To register a route for a viewset, the ...