David Brown David Brown - 3 months ago 93
Python Question

Exclude URLs from Django REST Swagger

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.

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

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


How could I go about doing this?

Thanks in advance for any help offered :P

Answer

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

So for example, in your case:

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")),
              ...
              )

and in your settings.py:

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

This is well described in there