REST framework 提供了两个 router
- SimpleRouter
- DefaultRouter
区别是,DefaultRouter 会多附带一个 API 根视图,返回一个包含所有列表响应数据。
总路由
from django.contrib import admin
from django.urls import path, include
from categories.views import CategoryViewSet
from rest_framework.routers import DefaultRouter
router = DefaultRouter()
router.register(r'categories', CategoryViewSet)
urlpatterns = [
path('', include(router.urls)),
path('admin/', admin.site.urls),
]
![1.png](https://a...