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)
Use handy request. build_absolute_uri() method on request, pass it the relative url and it'll give you full one. By default, the absolute URL for request. get_full_path() is returned, but you can pass it a relative URL as the first argument to convert it to an absolute URL.
In Django, views are Python functions which take a URL request as parameter and return an HTTP response or throw an exception like 404. Each view needs to be mapped to a corresponding URL pattern. This is done via a Python module called URLConf(URL configuration) Let the project name be myProject.
Django runs through each URL pattern, in order, and stops at the first one that matches the requested URL, matching against path_info . Once one of the URL patterns matches, Django imports and calls the given view, which is a Python function (or a class-based view).
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With