diff options
| author | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2010-09-11 03:13:23 +0000 |
|---|---|---|
| committer | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2010-09-11 03:13:23 +0000 |
| commit | fffe0a00a383f46fdfb8de44d56f8ae2e2ee09de (patch) | |
| tree | 53d854c5e2221ae8b8b352a9ac673ba7e2b2c81c /django/views/generic/simple.py | |
| parent | 04f50c1f281e1864576dc6ff5f4d89b562f82b6d (diff) | |
Add option to redirect_to view to allow passing along the query string
from the original request. Default is current behaviour, which is not to
pass the query string (it often won't be appropriate to do so).
Thanks to steingrd@ifi.uio.no for the patch and tests. Fixed #9966.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@13746 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/views/generic/simple.py')
| -rw-r--r-- | django/views/generic/simple.py | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/django/views/generic/simple.py b/django/views/generic/simple.py index 3b5309df96..435cd7623d 100644 --- a/django/views/generic/simple.py +++ b/django/views/generic/simple.py @@ -17,7 +17,7 @@ def direct_to_template(request, template, extra_context=None, mimetype=None, **k t = loader.get_template(template) return HttpResponse(t.render(c), mimetype=mimetype) -def redirect_to(request, url, permanent=True, **kwargs): +def redirect_to(request, url, permanent=True, query_string=False, **kwargs): """ Redirect to a given URL. @@ -33,7 +33,15 @@ def redirect_to(request, url, permanent=True, **kwargs): If the ``permanent`` argument is False, then the response will have a 302 HTTP status code. Otherwise, the status code will be 301. + + If the ``query_string`` argument is True, then the GET query string + from the request is appended to the URL. + """ + args = request.META["QUERY_STRING"] + if args and query_string and url is not None: + url = "%s?%s" % (url, args) + if url is not None: klass = permanent and HttpResponsePermanentRedirect or HttpResponseRedirect return klass(url % kwargs) |
