...

/

Adding a Router

Adding a Router

Learn how to create routes in Django and how to send http requests to RESTful API using Insomnia.

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 routers
from core.user.viewsets import UserViewSet
router = routers.SimpleRouter()
# ##################################################################### #
# ################### USER ###################### #
# ##################################################################### #
router.register(r'user', UserViewSet, basename='user')
urlpatterns = [
*router.urls,
]

To register a route for a viewset, the ...