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})