python - Determine complete Django url configuration -
is there way complete django url configuration?
for illustration django's debugging 404 page not show included url configs, not finish configuration.
answer: alasdair, here illustration script:
import urls def show_urls(urllist, depth=0): entry in urllist: print " " * depth, entry.regex.pattern if hasattr(entry, 'url_patterns'): show_urls(entry.url_patterns, depth + 1) show_urls(urls.urlpatterns)
django python, introspection friend.
in shell, import urls. looping through urls.urlpatterns, , drilling downwards through many layers of included url configurations possible, can build finish url configuration.
>import urls >urls.urlpatterns the list urls.urlpatterns contains regexurlpattern , regexurlresolver objects.
for regexurlpattern object p can display regular look with
>p.regex.pattern for regexurlresolver object q, represents included url configuration, can display first part of regular look with
>q.regex.pattern and use
>q.urlpatterns which homecoming farther list of regexurlresolver , regexurlpattern objects.
python django url
No comments:
Post a Comment