Django小練習
阿新 • • 發佈:2017-12-19
ren blog als pos .html url turn false ()
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})
Django小練習