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='介面文件')) ]