Django : How can I see a list of urlpatterns?

后端 未结 16 1698
有刺的猬
有刺的猬 2020-11-29 19:36

How can I see the current urlpatterns that \"reverse\" is looking in?

I\'m calling reverse in a view with an argument that I think should work, but doesn\'t. Any wa

16条回答
  •  自闭症患者
    2020-11-29 19:45

    There is a recipe on activestate

    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.url_patterns)
    

提交回复
热议问题