从 Django REST Swagger 中排除 URL

Exclude URLs from Django REST Swagger(从 Django REST Swagger 中排除 URL)

本文介绍了从 Django REST Swagger 中排除 URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从我的 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
}

这在那里有很好的描述

这篇关于从 Django REST Swagger 中排除 URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:从 Django REST Swagger 中排除 URL

基础教程推荐