Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #17076 -- When reversing a URL fails, inform the user which pat…

…terns were tried.
  • Loading branch information...
commit 8365ed08b83591bf6d7ddb3b3cb066d8325573bb 1 parent 0f3f88e
Wilfred Hughes authored June 13, 2013 mjtamlyn committed June 14, 2013
5  django/core/urlresolvers.py
@@ -422,8 +422,11 @@ def _reverse_with_prefix(self, lookup_view, _prefix, *args, **kwargs):
422 422
             lookup_view_s = "%s.%s" % (m, n)
423 423
         else:
424 424
             lookup_view_s = lookup_view
  425
+
  426
+        patterns = [pattern for (possibility, pattern, defaults) in possibilities]
425 427
         raise NoReverseMatch("Reverse for '%s' with arguments '%s' and keyword "
426  
-                "arguments '%s' not found." % (lookup_view_s, args, kwargs))
  428
+                "arguments '%s' not found. %d pattern(s) tried: %s" %
  429
+                             (lookup_view_s, args, kwargs, len(patterns), patterns))
427 430
 
428 431
 class LocaleRegexURLResolver(RegexURLResolver):
429 432
     """
14  tests/urlpatterns_reverse/tests.py
@@ -192,6 +192,20 @@ def test_non_urlsafe_prefix_with_args(self):
192 192
         self.assertEqual('/%7Eme/places/1/',
193 193
                 reverse('places', args=[1], prefix='/~me/'))
194 194
 
  195
+    def test_patterns_reported(self):
  196
+        # Regression for #17076
  197
+        try:
  198
+            # this url exists, but requires an argument
  199
+            reverse("people", args=[])
  200
+        except NoReverseMatch as e:
  201
+            pattern_description = r"1 pattern(s) tried: ['people/(?P<name>\\w+)/$']"
  202
+            self.assertIn(pattern_description, str(e))
  203
+        else:
  204
+            # we can't use .assertRaises, since we want to inspect the
  205
+            # exception
  206
+            self.fail("Expected a NoReverseMatch, but none occurred.")
  207
+
  208
+
195 209
 class ResolverTests(unittest.TestCase):
196 210
     def test_resolver_repr(self):
197 211
         """

0 notes on commit 8365ed0

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