user/urls.py
ModelViewSet注册路由三部曲
from django.urls import include, path
from user import views
from rest_framework.routers import SimpleRouter, DefaultRouter
# 自动生成路由方法, 必须使用视图集 # router = SimpleRouter() # 没有根路由 /user/ 无法识别
router = DefaultRouter() # 1.有根路由
router.register(r'user', views.UserViewSet) # 2.配置路由
urlpatterns = [
path('index/', views.index),
path('api-auth/', include('rest_framework.urls', namespace='rest_framework')) # 认证地址
]
urlpatterns += router.urls # 3.模块地址