Determine complete Django url configuration


Is there a way to get the complete django url configuration?

For example Django's debugging 404 page does not show included url configs, so this is not the complete configuration.

Answer: Thanks to Alasdair, here is an example script:

import urls

def show_urls(urllist, depth=0):
    for entry in urllist:
        print "  " * depth, entry.regex.pattern
        if hasattr(entry, 'url_patterns'):
            show_urls(entry.url_patterns, depth + 1)

12/19/2015 8:16:37 AM

Accepted Answer

Django is Python, so introspection is your friend.

In the shell, import urls. By looping through urls.urlpatterns, and drilling down through as many layers of included url configurations as possible, you can build the complete url configuration.

import urls

The list urls.urlpatterns contains RegexURLPattern and RegexURLResolver objects.

For a RegexURLPattern object p you can display the regular expression with


For a RegexURLResolver object q, which represents an included url configuration, you can display the first part of the regular expression with


Then use


which will return a further list of RegexURLResolver and RegexURLPattern objects.

10/12/2016 2:10:16 PM

Django extensions provides a utility to do this as a command.

pip install django-extensions

Then add django_extensions to your INSTALLED_APPS in then from the console just type the following

python show_urls

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow