从 Django REST Swagger 中排除 URL

2022-01-22 00:00:00 python django rest swagger

问题描述

我想从我的 REST API 文档中排除一些 URL.我正在使用 Django REST Swagger 和我能找到的唯一文档 (https://github.com/marcgibbons/django-rest-swagger) 并没有真正告诉我太多.settings.py 中有 SWAGGER_SETTINGS 的exclude_namespaces"部分,但没有真正的解释或示例说明如何使用它.

I have a few URLs that I want to exclude from my REST API documentation. I'm using Django REST Swagger and the only documentation I can find (https://github.com/marcgibbons/django-rest-swagger) doesn't really tell me much. There is the "exclude_namespaces" part of SWAGGER_SETTINGS in settings.py, but there is no real explanation or example of how to use this.

简单地说,我想从文档中排除以以下内容开头的所有 URL:

Simply put, I want to exclude any URLs from the docs that start with the following:

/api/jobs/status/
/api/jobs/parameters/

我该怎么做呢?

提前感谢您提供的任何帮助:P

Thanks in advance for any help offered :P


解决方案

要排除的命名空间是您的 urls.py 中定义的命名空间.

the namespaces to exclude are the one defined in your urls.py.

例如,在你的情况下:

urls.py:

internal_apis = patterns('',
                     url(r'^/api/jobs/status/',...),
                     url(r'^/api/jobs/parameters/',...),
                     )

urlpatterns = urlpatterns + patterns('',
              url(r'^', include(internal_apis, namespace="internal_apis")),
              ...
              )

在你的 settings.py 中:

and in your settings.py:

SWAGGER_SETTINGS = {
    "exclude_namespaces": ["internal_apis"],    #  List URL namespaces to ignore
}

这在那里有很好的描述

相关文章