summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorGrzegorz Nosek <root@localdomain.pl>2014-02-15 14:41:01 +0100
committerHonza Král <honza.kral@gmail.com>2014-02-15 15:56:04 +0100
commit79558c787ebfd0fe723acb061a375b19a27f18cd (patch)
treeb16a9c3ba02a78e3c8750449d8ae141a993b5198 /django
parent8bbdcc76e4a84cde92b8dbfd01581d098bd2187d (diff)
Fixed #18373 - improved handling of Resolver404s from views
When django.core.urlresolvers.resolve was called from a view, failed and the exception was propagated and rendered by technical_404_response, the URL mentioned on the page was the current URL instead of the URL passed to resolve(). Fixed by using the path attribute from the Resolver404 exception instead of request.path_info. Also cleaned up the exceptions to use standard named parameters instead of stuffing a dict in args[0]
Diffstat (limited to 'django')
-rw-r--r--django/core/urlresolvers.py11
-rw-r--r--django/views/debug.py8
2 files changed, 12 insertions, 7 deletions
diff --git a/django/core/urlresolvers.py b/django/core/urlresolvers.py
index 1dca15b4aa..e9bb441b3d 100644
--- a/django/core/urlresolvers.py
+++ b/django/core/urlresolvers.py
@@ -69,8 +69,11 @@ class ResolverMatch(object):
class Resolver404(Http404):
- pass
+ def __init__(self, path, tried=None):
+ super(Resolver404, self).__init__()
+ self.path = path
+ self.tried = tried
class NoReverseMatch(Exception):
pass
@@ -322,7 +325,7 @@ class RegexURLResolver(LocaleRegexProvider):
try:
sub_match = pattern.resolve(new_path)
except Resolver404 as e:
- sub_tried = e.args[0].get('tried')
+ sub_tried = e.tried
if sub_tried is not None:
tried.extend([pattern] + t for t in sub_tried)
else:
@@ -333,8 +336,8 @@ class RegexURLResolver(LocaleRegexProvider):
sub_match_dict.update(sub_match.kwargs)
return ResolverMatch(sub_match.func, sub_match.args, sub_match_dict, sub_match.url_name, self.app_name or sub_match.app_name, [self.namespace] + sub_match.namespaces)
tried.append([pattern])
- raise Resolver404({'tried': tried, 'path': new_path})
- raise Resolver404({'path': path})
+ raise Resolver404(new_path, tried=tried)
+ raise Resolver404(path)
@property
def urlconf_module(self):
diff --git a/django/views/debug.py b/django/views/debug.py
index d665c4e36b..2fb15ac34f 100644
--- a/django/views/debug.py
+++ b/django/views/debug.py
@@ -475,9 +475,11 @@ class ExceptionReporter(object):
def technical_404_response(request, exception):
"Create a technical 404 error response. The exception should be the Http404."
try:
- tried = exception.args[0]['tried']
- except (IndexError, TypeError, KeyError):
+ tried = exception.tried
+ error_url = exception.path
+ except AttributeError:
tried = []
+ error_url = request.path_info[1:] # Trim leading slash
else:
if (not tried # empty URLconf
or (request.path == '/'
@@ -494,7 +496,7 @@ def technical_404_response(request, exception):
c = Context({
'urlconf': urlconf,
'root_urlconf': settings.ROOT_URLCONF,
- 'request_path': request.path_info[1:], # Trim leading slash
+ 'request_path': error_url,
'urlpatterns': tried,
'reason': force_bytes(exception, errors='replace'),
'request': request,