Determine complete Django url configuration
Django extensions provides a utility to do this as a manage.py command.
pip install django-extensions
Then add django_extensions
to your INSTALLED_APPS in settings.py
. then from the console just type the following
python manage.py show_urls
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
The list urls.urlpatterns
contains RegexURLPattern
and RegexURLResolver
objects.
For a RegexURLPattern
object p
you can display the regular expression with
p.regex.pattern
For a RegexURLResolver
object q
, which represents an included url configuration, you can display the first part of the regular expression with
q.regex.pattern
Then use
q.url_patterns
which will return a further list of RegexURLResolver
and RegexURLPattern
objects.