Forked from ashishtajane/django urlpattern list .py
Last active
February 8, 2024 20:40
-
-
Save mjumbewu/03a6487fd12179173e80c6946b3ae8a4 to your computer and use it in GitHub Desktop.
Get all URL patterns in django
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Open django shell and do following. | |
from django.urls import get_resolver | |
def show_urls(urllist, depth=0): | |
for entry in urllist: | |
print(' ' * depth, entry.pattern) | |
if hasattr(entry, 'url_patterns'): | |
show_urls(entry.url_patterns, depth + 1) | |
show_urls(get_resolver().url_patterns) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment