1👍
There is a script made by @Cesar Canassa and it goes like this:
from django.conf import settings
from django.urls import URLPattern, URLResolver
urlconf = __import__(settings.ROOT_URLCONF, {}, {}, [''])
def list_urls(lis, acc=None):
if acc is None:
acc = []
if not lis:
return
l = lis[0]
if isinstance(l, URLPattern):
yield acc + [str(l.pattern)]
elif isinstance(l, URLResolver):
yield from list_urls(l.url_patterns, acc + [str(l.pattern)])
yield from list_urls(lis[1:], acc)
for p in list_urls(urlconf.urlpatterns):
print(''.join(p))
This code prints all URLs, unlike some other solutions it will print the full path and not only the last node. In case you want to add names
you change
yield acc + [str(l.pattern)]
print(''.join(p))
with:
yield acc + [str(l.pattern)], l.callback
print(''.join(p[0]))
but keep in mind that this prints out the view’s function name and not a name
Source:stackexchange.com