【问题标题】:How to generate swagger documentation for 'other' URLconfs from apps included into the project urls.py如何从项目 urls.py 中包含的应用程序中为“其他”URLconfs 生成 swagger 文档
【发布时间】:2019-10-24 23:16:54
【问题描述】:

我正在使用以下依赖项开发一个项目:

Python 3.7

django 2.2.6

djangorestframework 3.9.4

我正在创建多个应用程序,每个应用程序都有自己的 urls.py 文件,这些文件包含在父项目的 URLs 文件中。我希望为包含的 URLconf 文件中描述的 API 端点创建 swagger 文档。但是,swagger 只记录在父 URLconf 文件中映射的 URL。

我已经尝试在项目的 URLconfs 中包含 swagger 视图,但它仍然只服务于父 URLconf。

基本上,我已将以下代码添加到我所有的 URLconf 中

from rest_framework_swagger.views import get_swagger_view

schema_view = get_swagger_view(title='Some APIs')

urlpatterns = [
    path('', schema_view),
]

【问题讨论】:

    标签: django django-rest-framework swagger


    【解决方案1】:

    这成功了:

    from rest_framework.documentation import include_docs_urls
    
    urlpatterns = [
        path('docs/', include_docs_urls(title=API_TITLE, description=API_DESCRIPTION))
    ]
    

    【讨论】:

      猜你喜欢
      • 2020-03-07
      • 1970-01-01
      • 2011-01-04
      • 1970-01-01
      • 1970-01-01
      • 2019-12-19
      • 2018-09-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多