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) show_urls(urls.urlpatterns)
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 urls.urlpatterns
p you can display the regular expression with
q, which represents an included url configuration, you can display the first part of the regular expression with
which will return a further list of
Django extensions provides a utility to do this as a manage.py command.
pip install django-extensions
django_extensions to your INSTALLED_APPS in
settings.py. then from the console just type the following
python manage.py show_urls