mirror of
https://github.com/django/django.git
synced 2024-12-23 01:25:58 +00:00
Fixed #8221: added some better NoReverseMatch
error strings. Thanks, mrts.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@8672 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
10244d1c04
commit
a46d3ebfcc
1
AUTHORS
1
AUTHORS
@ -383,6 +383,7 @@ answer newbie questions, and generally made Django that much better:
|
|||||||
Swaroop C H <http://www.swaroopch.info>
|
Swaroop C H <http://www.swaroopch.info>
|
||||||
Aaron Swartz <http://www.aaronsw.com/>
|
Aaron Swartz <http://www.aaronsw.com/>
|
||||||
Ville Säävuori <http://www.unessa.net/>
|
Ville Säävuori <http://www.unessa.net/>
|
||||||
|
Mart Sõmermaa <http://mrts.pri.ee/>
|
||||||
Christian Tanzer <tanzer@swing.co.at>
|
Christian Tanzer <tanzer@swing.co.at>
|
||||||
Tyler Tarabula <tyler.tarabula@gmail.com>
|
Tyler Tarabula <tyler.tarabula@gmail.com>
|
||||||
Tyson Tate <tyson@fallingbullets.com>
|
Tyson Tate <tyson@fallingbullets.com>
|
||||||
|
@ -52,6 +52,8 @@ def get_callable(lookup_view, can_fail=False):
|
|||||||
mod_name, func_name = get_mod_func(lookup_view)
|
mod_name, func_name = get_mod_func(lookup_view)
|
||||||
if func_name != '':
|
if func_name != '':
|
||||||
lookup_view = getattr(__import__(mod_name, {}, {}, ['']), func_name)
|
lookup_view = getattr(__import__(mod_name, {}, {}, ['']), func_name)
|
||||||
|
if not callable(lookup_view):
|
||||||
|
raise AttributeError("'%s.%s' is not a callable." % (mod_name, func_name))
|
||||||
except (ImportError, AttributeError):
|
except (ImportError, AttributeError):
|
||||||
if not can_fail:
|
if not can_fail:
|
||||||
raise
|
raise
|
||||||
@ -196,10 +198,12 @@ class RegexURLPattern(object):
|
|||||||
mod_name, func_name = get_mod_func(viewname)
|
mod_name, func_name = get_mod_func(viewname)
|
||||||
try:
|
try:
|
||||||
lookup_view = getattr(__import__(mod_name, {}, {}, ['']), func_name)
|
lookup_view = getattr(__import__(mod_name, {}, {}, ['']), func_name)
|
||||||
except (ImportError, AttributeError):
|
except ImportError, e:
|
||||||
raise NoReverseMatch
|
raise NoReverseMatch("Could not import '%s': %s" % (mod_name, e))
|
||||||
|
except AttributeError, e:
|
||||||
|
raise NoReverseMatch("'%s' has no attribute '%s'" % (mod_name, func_name))
|
||||||
if lookup_view != self.callback:
|
if lookup_view != self.callback:
|
||||||
raise NoReverseMatch
|
raise NoReverseMatch("Reversed view '%s' doesn't match the expected callback ('%s')." % (viewname, self.callback))
|
||||||
return self.reverse_helper(*args, **kwargs)
|
return self.reverse_helper(*args, **kwargs)
|
||||||
|
|
||||||
def reverse_helper(self, *args, **kwargs):
|
def reverse_helper(self, *args, **kwargs):
|
||||||
@ -279,11 +283,12 @@ class RegexURLResolver(object):
|
|||||||
def reverse(self, lookup_view, *args, **kwargs):
|
def reverse(self, lookup_view, *args, **kwargs):
|
||||||
try:
|
try:
|
||||||
lookup_view = get_callable(lookup_view, True)
|
lookup_view = get_callable(lookup_view, True)
|
||||||
except (ImportError, AttributeError):
|
except (ImportError, AttributeError), e:
|
||||||
raise NoReverseMatch("'%s' is not a callable." % lookup_view)
|
raise NoReverseMatch("Error importing '%s': %s." % (lookup_view, e))
|
||||||
if lookup_view in self.reverse_dict:
|
if lookup_view in self.reverse_dict:
|
||||||
return u''.join([reverse_helper(part.regex, *args, **kwargs) for part in self.reverse_dict[lookup_view]])
|
return u''.join([reverse_helper(part.regex, *args, **kwargs) for part in self.reverse_dict[lookup_view]])
|
||||||
raise NoReverseMatch("Reverse for '%s' not found." % lookup_view)
|
raise NoReverseMatch("Reverse for '%s' with arguments '%s' and keyword "
|
||||||
|
"arguments '%s' not found." % (lookup_view, args, kwargs))
|
||||||
|
|
||||||
def reverse_helper(self, lookup_view, *args, **kwargs):
|
def reverse_helper(self, lookup_view, *args, **kwargs):
|
||||||
sub_match = self.reverse(lookup_view, *args, **kwargs)
|
sub_match = self.reverse(lookup_view, *args, **kwargs)
|
||||||
|
Loading…
Reference in New Issue
Block a user