drf路由【示例】
根urls.py
from django.contrib import admin
from django.urls import path, include, re_path
from django.views.static import serve
from django.conf import settings
urlpatterns = [
# path('admin/', admin.site.urls),
path('api/shipper/', include('apps.shipper.urls')),
re_path(r"^media/(?P<path>.*)$", serve, {'document_root': settings.MEDIA_ROOT}, name='media')
]
自定义app/urls.py
(如果外层套app文件夹,要改apps.py文件中的name)
from django.urls import path
from apps.shipper.views import account, basic, auth
from rest_framework.routers import SimpleRouter
router = SimpleRouter()
router.register(r'basic', basic.BasicView)
router.register(r'auth', auth.AuthView)
urlpatterns = [
path('register/send/sms/', account.RegisterSendSmsView.as_view()),
path('register/', account.RegisterView.as_view()),
path('login/pwd/', account.LoginPwdView.as_view()),
path('login/send/sms/', account.LoginSendSmsView.as_view()),
path('login/sms/', account.LoginSmsView.as_view()),
]
urlpatterns += router.urls