Exclude URLs from Django REST Swagger Exclude URLs from Django REST Swagger django django

Exclude URLs from Django REST Swagger


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


For all of those who found the above answer not helpful:I guess that "exclude_namespaces" doesn't work anymore in new versions of django swagger. I had almost the same problem (I didnt't want to show my internal apis in documentation) and the above solution didn't work for me. I've been searching for like an hour for a solution and finally found something helpful.

There are some attributes that you can pass to SchemaGenerator. One of them is urlconf. You can set it to be "yourproject.api.urls" and it will get only urls defined there! Of course, you have to make sure that all the urls that you want to exclude from your api documentation are not included there.

I hope that at least one person found my answer helpful ;).

A problem comes when you want to have many urls.py included in your api documentation. I don't know what should be done then. If anyone comes up with an answer to this new problem - feel free to comment my answer. thanks!


With new version of django swagger, we don't need to create view to exclude some urls. Below code will disable test2 url.

from rest_framework_swagger.views import get_swagger_viewurlpatterns1 = [    url(r'^', include(router.urls)),    url(r'^test/', include('test.urls')),    url(r'^test1/', Test2.as_view()),]schema_view = get_swagger_view(title='API Documentation', patterns=urlpatterns1)urlpatterns = urlpatterns1 + [    url(r'^docs/', schema_view),    url(r'^test2/', Test2.as_view()),]