Ticket #8221: improved_exceptions_for_reverse_with-args.diff
File improved_exceptions_for_reverse_with-args.diff, 2.1 KB (added by , 16 years ago) |
---|
-
django/core/urlresolvers.py
52 52 mod_name, func_name = get_mod_func(lookup_view) 53 53 if func_name != '': 54 54 lookup_view = getattr(__import__(mod_name, {}, {}, ['']), func_name) 55 if not callable(lookup_view): 56 raise AttributeError("'%s' in module '%s' is not a callable." 57 % (func_name, mod_name)) 55 58 except (ImportError, AttributeError): 56 59 if not can_fail: 57 60 raise … … 197 200 try: 198 201 lookup_view = getattr(__import__(mod_name, {}, {}, ['']), func_name) 199 202 except (ImportError, AttributeError): 200 raise NoReverseMatch 203 raise NoReverseMatch("Error importing '%s': %s." % (viewname, e)) 201 204 if lookup_view != self.callback: 202 raise NoReverseMatch 205 raise NoReverseMatch("Imported '%s' doesn't match the expected function." % viewname) 203 206 return self.reverse_helper(*args, **kwargs) 204 207 205 208 def reverse_helper(self, *args, **kwargs): … … 284 287 def reverse(self, lookup_view, *args, **kwargs): 285 288 try: 286 289 lookup_view = get_callable(lookup_view, True) 287 except (ImportError, AttributeError) :288 raise NoReverseMatch(" '%s' is not a callable." % lookup_view)290 except (ImportError, AttributeError), e: 291 raise NoReverseMatch("Error importing '%s': %s." % (lookup_view, e)) 289 292 if lookup_view in self.reverse_dict: 290 293 return u''.join([reverse_helper(part.regex, *args, **kwargs) for part in self.reverse_dict[lookup_view]]) 291 raise NoReverseMatch("Reverse for '%s' not found." % lookup_view) 294 raise NoReverseMatch("Reverse for '%s' with arguments '%s' and keyword " 295 "arguments '%s' not found." % (lookup_view, args, kwargs)) 292 296 293 297 def reverse_helper(self, lookup_view, *args, **kwargs): 294 298 sub_match = self.reverse(lookup_view, *args, **kwargs)