diff --git a/django/views/generic/base.py b/django/views/generic/base.py index 6dfbc7a9da..fcdc7c785b 100644 --- a/django/views/generic/base.py +++ b/django/views/generic/base.py @@ -139,12 +139,11 @@ class RedirectView(View): are provided as kwargs to this method. """ if self.url: + url = self.url % kwargs args = self.request.META.get('QUERY_STRING', '') if args and self.query_string: - url = "%s?%s" % (self.url, args) - else: - url = self.url - return url % kwargs + url = "%s?%s" % (url, args) + return url else: return None diff --git a/tests/regressiontests/generic_views/base.py b/tests/regressiontests/generic_views/base.py index e7aeaf9cde..6528dc6723 100644 --- a/tests/regressiontests/generic_views/base.py +++ b/tests/regressiontests/generic_views/base.py @@ -283,6 +283,13 @@ class RedirectViewTest(unittest.TestCase): self.assertEqual(response.status_code, 301) self.assertEqual(response['Location'], '/bar/?pork=spam') + def test_include_urlencoded_args(self): + "GET arguments can be URL-encoded when included in the redirected URL" + response = RedirectView.as_view(url='/bar/', query_string=True)( + self.rf.get('/foo/?unicode=%E2%9C%93')) + self.assertEqual(response.status_code, 301) + self.assertEqual(response['Location'], '/bar/?unicode=%E2%9C%93') + def test_parameter_substitution(self): "Redirection URLs can be parameterized" response = RedirectView.as_view(url='/bar/%(object_id)d/')(self.rf.get('/foo/42/'), object_id=42)