Router Example

A snippet showing how to use routers with DRF ViewSets.


# urls.py

from django.urls import path, include
from rest_framework.routers import DefaultRouter
from .views import ArticleViewSet

router = DefaultRouter()
router.register(r"articles", ArticleViewSet, basename="article")

urlpatterns = [
    path("api/", include(router.urls)),
]
      
Explanation:
  • Router auto-generates standard CRUD routes (list/create/retrieve/update/destroy).
Never miss a story on Django.wiki

Subscribe for fresh tutorials, snippets, and updates.

By subscribing you agree to our Privacy Policy.