REST framework:接口文档的配置与生成
REST framework通过第三方库可以自动帮助我们生成网页版的接口文档,自动接口文档能生成的是继承自APIView
及其子类的视图
pip install coreapi -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com
INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', # 注册应用 'coreapi', ]
REST_FRAMEWORK = { # 接口文档配置 'DEFAULT_SCHEMA_CLASS': 'rest_framework.schemas.coreapi.AutoSchema', }
from rest_framework.documentation import include_docs_urls urlpatterns = [ re_path(r'^docs/', include_docs_urls(title='接口文档')) ]
知道、想到、做到、得到