drf-ViewSet之路由简写的方法
https://www.bilibili.com/video/BV1z5411D7BQ?p=20&spm_id_from=pageDriver&vd_source=caabcbd2a759a67e2a3de8acbaaf08ea
url.py
from django.contrib import admin
from django.urls import path,re_path
# 应用的视图层
from sers import views
from django.urls import re_path as url
from rest_framework import routers
#1、注册路由进去
router=routers.DefaultRouter()
router.register('book',views.BookView)
urlpatterns = [
path('admin/', admin.site.urls),
# # 新
# url('^book/$', views.BookView.as_view({"get":"list","post":"create"})),
# # 新
# # 加有名分组?P<pk>
# url('^book/(?P<pk>\d+)/$', views.BookView.as_view({"get":"retrieve","put":"update","delete":"destroy"})),
]
#2、 把路由驾到路由列表里即可,就自动生成了上面2条路由
urlpatterns += router.urls
主要是下面这些
from rest_framework import routers
#1、注册路由进去
router=routers.DefaultRouter()
router.register('book',views.BookView)
urlpatterns = []
# 把路由驾到路由列表里即可,就自动生成了上面2条路由
urlpatterns += router.urls