Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
  • Loading branch information...
commit a46d3ebfccdd47dd8c915125d0ba5f29b88ffe08 1 parent 10244d1
Jacob Kaplan-Moss authored August 28, 2008
1  AUTHORS
@@ -383,6 +383,7 @@ answer newbie questions, and generally made Django that much better:
383 383
     Swaroop C H <http://www.swaroopch.info>
384 384
     Aaron Swartz <http://www.aaronsw.com/>
385 385
     Ville Säävuori <http://www.unessa.net/>
  386
+    Mart Sõmermaa <http://mrts.pri.ee/>
386 387
     Christian Tanzer <tanzer@swing.co.at>
387 388
     Tyler Tarabula <tyler.tarabula@gmail.com>
388 389
     Tyson Tate <tyson@fallingbullets.com>
17  django/core/urlresolvers.py
@@ -52,6 +52,8 @@ def get_callable(lookup_view, can_fail=False):
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.%s' is not a callable." % (mod_name, func_name))
55 57
         except (ImportError, AttributeError):
56 58
             if not can_fail:
57 59
                 raise
@@ -196,10 +198,12 @@ def reverse(self, viewname, *args, **kwargs):
196 198
         mod_name, func_name = get_mod_func(viewname)
197 199
         try:
198 200
             lookup_view = getattr(__import__(mod_name, {}, {}, ['']), func_name)
199  
-        except (ImportError, AttributeError):
200  
-            raise NoReverseMatch
  201
+        except ImportError, e:
  202
+            raise NoReverseMatch("Could not import '%s': %s" % (mod_name, e))
  203
+        except AttributeError, e:
  204
+            raise NoReverseMatch("'%s' has no attribute '%s'" % (mod_name, func_name))
201 205
         if lookup_view != self.callback:
202  
-            raise NoReverseMatch
  206
+            raise NoReverseMatch("Reversed view '%s' doesn't match the expected callback ('%s')." % (viewname, self.callback))
203 207
         return self.reverse_helper(*args, **kwargs)
204 208
 
205 209
     def reverse_helper(self, *args, **kwargs):
@@ -279,11 +283,12 @@ def resolve500(self):
279 283
     def reverse(self, lookup_view, *args, **kwargs):
280 284
         try:
281 285
             lookup_view = get_callable(lookup_view, True)
282  
-        except (ImportError, AttributeError):
283  
-            raise NoReverseMatch("'%s' is not a callable." % lookup_view)
  286
+        except (ImportError, AttributeError), e:
  287
+            raise NoReverseMatch("Error importing '%s': %s." % (lookup_view, e))
284 288
         if lookup_view in self.reverse_dict:
285 289
             return u''.join([reverse_helper(part.regex, *args, **kwargs) for part in self.reverse_dict[lookup_view]])
286  
-        raise NoReverseMatch("Reverse for '%s' not found." % lookup_view)
  290
+        raise NoReverseMatch("Reverse for '%s' with arguments '%s' and keyword "
  291
+                "arguments '%s' not found." % (lookup_view, args, kwargs))
287 292
 
288 293
     def reverse_helper(self, lookup_view, *args, **kwargs):
289 294
         sub_match = self.reverse(lookup_view, *args, **kwargs)

0 notes on commit a46d3eb

Please sign in to comment.
Something went wrong with that request. Please try again.