from django.urls import URLPattern
def get_all_urls(patterns, pre_fix, result):
for item in patterns:
part = item.pattern.regex.pattern.strip("^$")
if isinstance(item, URLPattern):
result.append(pre_fix + part)
else:
get_all_urls(item.url_patterns, pre_fix + part, result=result)
return result
if __name == "__main__":
# 项目根路由
from server import urls
print(get_all_urls(urls.urlpatterns, pre_fix="/", result=[]))
获取url
最新推荐文章于 2024-04-26 01:45:18 发布