diff options
| author | Adrian Holovaty <adrian@holovaty.com> | 2008-12-08 04:53:34 +0000 |
|---|---|---|
| committer | Adrian Holovaty <adrian@holovaty.com> | 2008-12-08 04:53:34 +0000 |
| commit | b76d7c1decb04cdb7ec363cd589f273952ab789a (patch) | |
| tree | 2fa7743da37cca1ae94cfaaa21f11d9e9c9ca935 /django | |
| parent | e9b90d98998da48d4ac18aabe135fa4200547be5 (diff) | |
Added a 'permanent' argument the simple.redirect_to() generic view. It's True by default, to match existing behavior. If set to False, the redirect will be a 302 instead of a 301. This is technically backwards-incompatible if you were using the redirect_to generic view with a format-string key called 'permanent', which is highly, highly unlikely.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@9594 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django')
| -rw-r--r-- | django/views/generic/simple.py | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/django/views/generic/simple.py b/django/views/generic/simple.py index 0a68b82a10..3b5309df96 100644 --- a/django/views/generic/simple.py +++ b/django/views/generic/simple.py @@ -1,5 +1,5 @@ from django.template import loader, RequestContext -from django.http import HttpResponse, HttpResponsePermanentRedirect, HttpResponseGone +from django.http import HttpResponse, HttpResponseRedirect, HttpResponsePermanentRedirect, HttpResponseGone def direct_to_template(request, template, extra_context=None, mimetype=None, **kwargs): """ @@ -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, **kwargs): +def redirect_to(request, url, permanent=True, **kwargs): """ Redirect to a given URL. @@ -30,8 +30,12 @@ def redirect_to(request, url, **kwargs): ) If the given url is ``None``, a HttpResponseGone (410) will be issued. + + If the ``permanent`` argument is False, then the response will have a 302 + HTTP status code. Otherwise, the status code will be 301. """ if url is not None: - return HttpResponsePermanentRedirect(url % kwargs) + klass = permanent and HttpResponsePermanentRedirect or HttpResponseRedirect + return klass(url % kwargs) else: return HttpResponseGone() |
