django rest framework 使用api接口文档
一、使用swagger生成api接口文档
1、pip install django-rest-swagger
2、url.py中配置
from rest_framework_swagger.views import get_swagger_view
schema_view = get_swagger_view(title='API 接口文档')
urlpatterns = [
path('docs/', schema_view, name='docs'), # 线上环境,干掉
]
3、在settings.py中添加下列配置
REST_FRAMEWORK = {
'DEFAULT_SCHEMA_CLASS': 'rest_framework.schemas.coreapi.AutoSchema'
}
4、访问url查看效果
5、未完待续
二、使用drf自带的api接口文档
相当简单和,直接在urls.py里引用即可
mysite/urls.py
from rest_framework.documentation import include_docs_urls
urlpatterns = [
path(r'docs/', include_docs_urls(title='STAR PAAS')),
]
mysite/settings.py
REST_FRAMEWORK = {
# api接口文档配置
'DEFAULT_SCHEMA_CLASS': 'rest_framework.schemas.coreapi.AutoSchema'
}
访问url:http://127.0.0.1:8005/docs/
参考:https://www.cnblogs.com/wanglei957/articles/11153144.html
三、drf-yasg
给每个分组增加说明参考:https://zhuanlan.zhihu.com/p/269499888