from rest_framework.versioning import URLPathVersioning,QueryParameterVersioning
源码解析:
使用路由配置
获取版本:
这个baseVersioning 默认配置:
获取version源码
可以去settting.py去配置全局使用:
REST_FRAMEWORK={
"versioning_class":"rest_framework.versioning.URLPathVersioning",
"DEFAULT_VERSION":"v1",
"ALLOWED_VERSIONS":["v1","v2"],
"VERSION_PARAM":"version"
}
注意VERSION_PARAM 系统默认的是version:
可以根据路由配置修改:
urlpatterns = [
url(r'^(?P<version>[v1|v2]+)/dog$', views.DogView.as_view()),
]
访问: