django查询项目里面的所有url

2018-08-15  本文已影响0人  lkning

from django.urls.resolvers import RegexURLPattern
from django.urls.resolvers import RegexURLResolver

from django.shortcuts import HttpResponse

url = []
def show_urls(urllist, footer=None):
    for entry in urllist:

        if hasattr(entry, 'url_patterns'):
            if entry.regex.pattern:
                show_urls(entry.url_patterns)
        else:
            url.append((entry.regex.pattern, entry.name))

show_urls(urlpatterns)
print(url)
上一篇下一篇

猜你喜欢

热点阅读