diff options
| author | Adrian Holovaty <adrian@holovaty.com> | 2005-08-05 22:22:41 +0000 |
|---|---|---|
| committer | Adrian Holovaty <adrian@holovaty.com> | 2005-08-05 22:22:41 +0000 |
| commit | 59c3ebc6dddab2a52b5c4079fb78871b35b5dcaa (patch) | |
| tree | 71295ede494f24ce9bba025a8c4642e134881ed1 /django/core/urlresolvers.py | |
| parent | c5179609847733c4babcc32312686d9fabf37315 (diff) | |
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
Diffstat (limited to 'django/core/urlresolvers.py')
| -rw-r--r-- | django/core/urlresolvers.py | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/django/core/urlresolvers.py b/django/core/urlresolvers.py index 50f9336171..178c2d139a 100644 --- a/django/core/urlresolvers.py +++ b/django/core/urlresolvers.py @@ -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, '', '', ['']) |
