Skip to content

Instantly share code, notes, and snippets.

@funkybob
Created September 14, 2023 00:17
Show Gist options
  • Save funkybob/49a9f40aad801f80b861e61baa8bc878 to your computer and use it in GitHub Desktop.
Save funkybob/49a9f40aad801f80b861e61baa8bc878 to your computer and use it in GitHub Desktop.
Code to dump list of default URL patterns for a Django app (run from manage.py shell)
from django.urls import get_resolver
res = get_resolver()
def get_patterns(m, prefix):
nprefix = prefix + (m.pattern.describe(),)
yield nprefix
for p in getattr(m, 'url_patterns', []):
yield from get_patterns(p, nprefix)
for p in get_patterns(res, ()):
print(' '.join(p))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment