Code that displays a list of URL names (the ones you put in the first argument of reverse ()) used by Django's URL parser (URL resolver)
from django.core.urlresolvers import get_resolver
root_resolver = get_resolver()
def _join_namespace(a, b):
return (a + ':' if a else '') + (b or '')
def _print_resolver(namespace, resolver):
_namespace = _join_namespace(namespace, resolver.namespace)
for ns, (prefix, res) in resolver.namespace_dict.items():
_print_resolver(_namespace, res)
for n, l in resolver.reverse_dict.items():
if callable(n):
continue
print(_join_namespace(_namespace, n))
_print_resolver('', root_resolver)
result
admin:blog_blogpost_delete
admin:blog_blogpost_add
admin:auth_user_changelist
admin:galleries_gallery_delete
admin:form_lottery_electedformentry_delete
admin:contact_contact_changelist
admin:redirects_redirect_add
admin:datastructure_datastructurepage_changelist
admin:forms_form_changelist
admin:pages_richtextpage_change
admin:pages_link_change
admin:blog_blogpost_change
admin:datastructure_datastructure_changelist
admin:datastructure_datastructure_history
admin:news_newscategory_delete
admin:auth_group_delete
admin:blog_blogcategory_history
admin:pages_richtextpage_changelist
admin:auth_user_add
admin:sites_site_change
admin:sites_site_changelist
admin:forms_form_delete
admin:form_lottery_electedformentry_changelist
admin:login
admin:galleries_gallery_add
admin:news_newsarticle_add
admin:conf_setting_change
admin:pages_page_change
admin:pages_page_changelist
admin:sites_site_delete
admin:redirects_redirect_history
admin:galleries_gallery_change
admin:blog_blogcategory_add
...
Recommended Posts