2
可能重複:
Determine complete Django url configuration如何從Django代碼訪問urls.py中的所有url?
怎麼能在你從Django代碼訪問的所有網址在urls.py?
我想要列出urls.py
中列出的所有網址,並在另一個Django視圖中遍歷它們。
可能重複:
Determine complete Django url configuration如何從Django代碼訪問urls.py中的所有url?
怎麼能在你從Django代碼訪問的所有網址在urls.py?
我想要列出urls.py
中列出的所有網址,並在另一個Django視圖中遍歷它們。
看到這個相關的StackOverflow question和answer。同樣在評論中,有人發帖this fantastic script:
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.urlpatterns)