配置django 接口文档docs

REST framework可以自动帮助我们生成接口文档
接口文档以网页的方式呈现
自动接口文档能生成的是继承自APIView及其子类的视图。

1、安装包

pip install coreapi

django在使用coreapi时AssertionError: coreapi must be installed for schema support.

pip install coreapi pyyaml

2、首先打开你的项目的urls,在里面导包:

from rest_framework.documentation import include_docs_urls

并在下面配置docs的路径:

url(r'docs/',include_docs_urls(title='接口文档')),

3、如果抛出如下异常:
link = view.schema.get_link(path, method, base_url=self.url)
AttributeError: ‘AutoSchema’ object has no attribute ‘get_link’
[01/Aug/2019 02:32:03] “GET /docs/ HTTP/1.1” 500 109358

在配置文件settings.py中重新指定schema_class的配置

REST_FRAMEWORK = {
	'DEFAULT_SCHEMA_CLASS': 'rest_framework.schemas.coreapi.AutoSchema',
    # 新版drf schema_class默认用的是rest_framework.schemas.openapi.AutoSchema
}

你可能感兴趣的:(Python,python,django)