Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
可能重复: 确定完整的 Django url 配置
如何从 Django 代码访问 urls.py 中的所有 url?
我想获取列出的所有 url 的列表,urls.py并在另一个 Django 视图中遍历它们。
urls.py
请参阅这个相关的 StackOverflow问题和答案。同样在评论中,有人发布了这个精彩的脚本:
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)