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

 

posted @ 2018-12-31 22:48  就俗人一个  阅读(200)  评论(0编辑  收藏  举报