Django小练习

1、获取系统所有Url

from django.urls.resolvers import RegexURLPattern 

#定义函数
def get_all_url(patterns, prev, is_first=False, result=[]):
    if is_first:
        result.clear()
    for item in patterns:
        v = item._regex.strip("^$")
        if isinstance(item, RegexURLPattern):
            result.append(prev + v)
        else:
            get_all_url(item.urlconf_name, prev + v)

    return result

#调用函数
def default(request):
    from pro_crm.urls import urlpatterns
    result = get_all_url(urlpatterns, prev='/', is_first=True)
    return render(request, "default.html", {"result": result})

  

posted @ 2017-12-18 18:50  hedeyong11  阅读(132)  评论(0编辑  收藏  举报