主路由文件
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path(‘admin/‘, admin.site.urls),
path(‘user/‘, include(‘user.urls‘)),
]
-- coding: utf-8 --
子路由文件
from django.urls import include, path
from user import views
from rest_framework.routers import SimpleRouter, DefaultRouter
自动生成路由方法,必须使用视图集
router=SimpleRouter() #没有根路由 /user/无法识别
router = DefaultRouter() # 有根路由
router.register(r‘user‘, views.UserViewSet) # 配置路由
urlpatterns = [
path(‘index/‘, views.index),
path(‘api-auth/‘, include(‘rest_framework.urls‘, namespace=‘rest_framework‘)) # 认证地址
]
urlpatterns += router.urls # 模块地址