"me too"답변을 추가 할 위험이 있으므로 위의 제출 된 스크립트의 수정 버전을 게시하여 프로젝트의 모든 URL을 나열하고 사전 순으로 정렬하고 사전 순으로 정렬 한보기를 제공합니다. 그들이 전화한다. 프로덕션 페이지보다 개발자 도구가 많습니다.
def all_urls_view(request):
from your_site.urls import urlpatterns #this import should be inside the function to avoid an import loop
nice_urls = get_urls(urlpatterns) #build the list of urls recursively and then sort it alphabetically
return render(request, "yourapp/links.html", {"links":nice_urls})
def get_urls(raw_urls, nice_urls=[], urlbase=''):
'''Recursively builds a list of all the urls in the current project and the name of their associated view'''
from operator import itemgetter
for entry in raw_urls:
fullurl = (urlbase + entry.regex.pattern).replace('^','')
if entry.callback: #if it points to a view
viewname = entry.callback.func_name
nice_urls.append({"pattern": fullurl,
"location": viewname})
else: #if it points to another urlconf, recur!
get_urls(entry.url_patterns, nice_urls, fullurl)
nice_urls = sorted(nice_urls, key=itemgetter('pattern')) #sort alphabetically
return nice_urls
및 템플릿 : 당신이로 (다시 당신이보기에 전달할 변수를 취하는 정규 표현식에의에 대한 입력 상자 목록을 렌더링 할 수있는 실제 공상을 얻고 싶었다 경우
<ul>
{% for link in links %}
<li>
{{link.pattern}} ----- {{link.location}}
</li>
{% endfor%}
</ul>
개발자 페이지).
매우 유용한 스크립트 덕분에 – RichVel