Skip to content

Commit

Permalink
Fixed #11960 -- Improved error message for redirects. Thanks, mattmcc
Browse files Browse the repository at this point in the history
git-svn-id: http://code.djangoproject.com/svn/django/trunk@12185 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
adrianholovaty committed Jan 10, 2010
1 parent cc25361 commit 2ef52d0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions django/shortcuts/__init__.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ def redirect(to, *args, **kwargs):
try: try:
return redirect_class(urlresolvers.reverse(to, args=args, kwargs=kwargs)) return redirect_class(urlresolvers.reverse(to, args=args, kwargs=kwargs))
except urlresolvers.NoReverseMatch: except urlresolvers.NoReverseMatch:
# If this is a callable, re-raise.
if callable(to):
raise
# If this doesn't "feel" like a URL, re-raise. # If this doesn't "feel" like a URL, re-raise.
if '/' not in to and '.' not in to: if '/' not in to and '.' not in to:
raise raise
Expand Down
6 changes: 6 additions & 0 deletions tests/regressiontests/urlpatterns_reverse/tests.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -165,6 +165,12 @@ def test_redirect_to_url(self):
res = redirect('http://example.com/') res = redirect('http://example.com/')
self.assertEqual(res['Location'], 'http://example.com/') self.assertEqual(res['Location'], 'http://example.com/')


def test_redirect_view_object(self):
from views import absolute_kwargs_view
res = redirect(absolute_kwargs_view)
self.assertEqual(res['Location'], '/absolute_arg_view/')
self.assertRaises(NoReverseMatch, redirect, absolute_kwargs_view, wrong_argument=None)



class NamespaceTests(TestCase): class NamespaceTests(TestCase):
urls = 'regressiontests.urlpatterns_reverse.namespace_urls' urls = 'regressiontests.urlpatterns_reverse.namespace_urls'
Expand Down

0 comments on commit 2ef52d0

Please sign in to comment.