Ticket #11960: 11960-1.diff

File 11960-1.diff, 1.3 KB (added by Matt McClanahan, 15 years ago)
  • django/shortcuts/__init__.py

     
    4949    try:
    5050        return redirect_class(urlresolvers.reverse(to, args=args, kwargs=kwargs))
    5151    except urlresolvers.NoReverseMatch:
     52        # If this is a callable, re-raise.
     53        if callable(to):
     54            raise
    5255        # If this doesn't "feel" like a URL, re-raise.
    5356        if '/' not in to and '.' not in to:
    5457            raise
  • tests/regressiontests/urlpatterns_reverse/tests.py

     
    160160        res = redirect('http://example.com/')
    161161        self.assertEqual(res['Location'], 'http://example.com/')
    162162
     163    def test_redirect_view_object(self):
     164        from views import absolute_kwargs_view
     165        res = redirect(absolute_kwargs_view)
     166        self.assertEqual(res['Location'], '/absolute_arg_view/')
     167        self.assertRaises(NoReverseMatch, redirect, absolute_kwargs_view, wrong_argument=None)
     168
    163169
    164170class NamespaceTests(TestCase):
    165171    urls = 'regressiontests.urlpatterns_reverse.namespace_urls'
Back to Top