Last active
February 8, 2024 20:40
-
-
Save ashishtajane/6531000f8c830717fe62 to your computer and use it in GitHub Desktop.
Get all URL patterns in django
This file contains 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. | |
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks, nice snippet ! slightly updated it for my current version of django (4.2)