标签:des code import back site round dmi router nbsp
当一个视图有list、create、retrieve、update、destroy所有的功能,路由组件可以用DRF自带的routers简写
项目总路由:pro/urls.py
from django.contrib import admin from django.urls import path, include urlpatterns = [ path(‘admin/‘, admin.site.urls), path(‘books/‘, include(‘books.urls‘)), ]
books/urls.py
from . import views from rest_framework.routers import DefaultRouter router = DefaultRouter() router.register(r"", views.BookModelView) urlpatterns = [] urlpatterns += router.urls
访问:http://127.0.0.1:8000/books/ 显示列表
访问:http://127.0.0.1:8000/books/1/ 显示单条记录
标签:des code import back site round dmi router nbsp
原文地址:https://www.cnblogs.com/staff/p/12602286.html