Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determine complete Django url configuration

Tags:

python

url

django

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) 
like image 980
Michael Avatar asked Dec 01 '09 19:12

Michael


People also ask

How can I get full URL in Django?

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.

What is URL configuration in Django?

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.

How will Django match URLs?

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).


1 Answers

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 
like image 166
Alan Viars Avatar answered Oct 19 '22 15:10

Alan Viars