Django REST framework 渲染器、版本
渲染器、版本:
# settings.py REST_FRAMEWORK = { "DEFAULT_RENDERER_CLASSES": [ "rest_framework.renderers.JSONRenderer", # "rest_framework.renderers.BrowsableAPIRenderer", ], "DEFAULT_VERSIONING_CLASS": "rest_framework.versioning.URLPathVersioning", "DEFAULT_VERSION": "v1", # 默认的版本 "ALLOWED_VERSIONS": ["v1", "v2"], # 允许的版本 }
版本urls.py:
urlpatterns = [ url(r"^api/(?P<version>\w+)/", include("api.urls")), ] urlpatterns = [ url(r"^course/", course.CourseView.as_view()), ]
获取版本: request.version