从 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Leetcode 234: Palindrome LinkedList(Leetcode 234:回文链接列表)
How do I read an Excel file directly from Dropbox#39;s API using pandas.read_excel()?(如何使用PANDAS.READ_EXCEL()直接从Dropbox的API读取Excel文件?)
subprocess.Popen tries to write to nonexistent pipe(子进程。打开尝试写入不存在的管道)
I want to realize Popen-code from Windows to Linux:(我想实现从Windows到Linux的POpen-code:)
Reading stdout from a subprocess in real time(实时读取子进程中的标准输出)
How to call type safely on a random file in Python?(如何在Python中安全地调用随机文件上的类型?)