1
0
mirror of https://github.com/django/django.git synced 2025-10-28 08:06:09 +00:00

Greatly improved the 404 error message when DEBUG=True. If none of the urlpatterns matches, Django now displays a list of all the urlpatterns it tried. This should catch a lot of newbie errors, and it's helpful even for power users.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@414 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Adrian Holovaty
2005-08-05 22:22:41 +00:00
parent c517960984
commit 59c3ebc6dd
2 changed files with 40 additions and 11 deletions

View File

@@ -10,6 +10,9 @@ a string) and returns a tuple in this format:
from django.core.exceptions import Http404, ViewDoesNotExist
import re
class Resolver404(Http404):
pass
def get_mod_func(callback):
# Converts 'django.views.news.stories.story_detail' to
# ['django.views.news.stories', 'story_detail']
@@ -52,15 +55,20 @@ class RegexURLResolver:
self.urlconf_name = urlconf_name
def resolve(self, path):
tried = []
match = self.regex.search(path)
if match:
new_path = path[match.end():]
for pattern in self.url_patterns:
sub_match = pattern.resolve(new_path)
if sub_match:
return sub_match
# None of the regexes matched, so raise a 404.
raise Http404, "Tried all URL patterns but didn't find a match for %r" % path
try:
sub_match = pattern.resolve(new_path)
except Resolver404, e:
tried.extend([(pattern.regex.pattern + ' ' + t) for t in e.args[0]['tried']])
else:
if sub_match:
return sub_match
tried.append(pattern.regex.pattern)
raise Resolver404, {'tried': tried, 'path': new_path}
def _get_urlconf_module(self):
self.urlconf_module = __import__(self.urlconf_name, '', '', [''])