swagger 文档django实现

https://books.agiliq.com/projects/django-api-polls-tutorial/en/latest/swagger.html#adding-swagger-documentation

添加swagger文档

安装django-rest-swagger

pip install django-rest-swagger

更新你的 settings.py

INSTALLED_APPS = [
    # ...
    'polls',
    'rest_framework_swagger',
]

向您的网址添加招摇。

from rest_framework_swagger.views import get_swagger_view

schema_view = get_swagger_view(title='Polls API')

# ...
urlpatterns = [
    # ...
    path(r'swagger-docs/', schema_view),
]

导航到/ swagger-docs /您的招贤纳士的文档已经准备就绪,所有的荣耀。

_images / swagger.png

使用coreapi进行文档编制

安装coreapi

pip install coreapi

将coreapi网址添加到您的网址中。

from rest_framework.documentation import include_docs_urls
# ...

urlpatterns = [
    # ...
    path(r'docs/', include_docs_urls(title='Polls API')),
]

并且您的coreapi文档已经准备就绪,所有的荣耀。

_images / coreapi.png
原文地址:https://www.cnblogs.com/SunshineKimi/p/14056950.html