REST_FRAMEWORK={ "DEFAULT_VERSIONING_CLASS": "rest_framework.versioning.URLPathVersioning", "DEFAULT_VERSION": 'v1', # 默认为1 "ALLOWED_VERSIONS": ['v1', 'v2'], # 仅允许v1或者v2访问 "VERSION_PARAM": 'version', }
urls
from django.urls import path, re_path from .views import BookView, PublsihView, AuhthorView,UserView,LoginView,HomeIndex,VueView urlpatterns = [ re_path(r'^(?P<version>[v1|v2]+)/vue/$',VueView.as_view({"get": 'list', 'post': 'create'})), re_path(r'^(?P<version>[v1|v2]+)/vue/(?P<id>[0-9]+)/$', VueView.as_view({'get': 'retrieve', 'patch': 'partial_update', 'delete': 'destroy'})), re_path(r'^(?P<version>[v1|v2]+)/book/$', BookView.as_view({"get": 'list', 'post': 'create'} ,name='book_list') ), re_path(r'^(?P<version>[v1|v2]+)/book/(?P<id>[0-9]+)/$', BookView.as_view( {'get': 'retrieve', 'patch': 'partial_update', 'delete': 'destroy'})), re_path('^(?P<version>[v1|v2]+)/author/$', AuhthorView.as_view({"get": 'list', 'post': 'create'}) ), re_path('^(?P<version>[v1|v2]+)/publish/$', PublsihView.as_view({"get": 'list', 'post': 'create'})), re_path('^(?P<version>[v1|v2]+)/regist/$', UserView.as_view({'post': 'create'}) ), re_path('^(?P<version>[v1|v2]+)/login/$', LoginView.as_view({'post': 'create'}) ), re_path('^(?P<version>[v1|v2]+)/test/$', HomeIndex.as_view() ), re_path('index/$', views.index, ), ]