Created
May 23, 2010 10:09
-
-
Save qoelet/410817 to your computer and use it in GitHub Desktop.
django.views.generic.simple
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def redirect_to(request, url, permanent=True, **kwargs): | |
""" | |
Redirect to a given URL. | |
The given url may contain dict-style string formatting, which will be | |
interpolated against the params in the URL. For example, to redirect from | |
``/foo/<id>/`` to ``/bar/<id>/``, you could use the following URLconf:: | |
urlpatterns = patterns('', | |
('^foo/(?P<id>\d+)/$', 'django.views.generic.simple.redirect_to', {'url' : '/bar/%(id)s/'}), | |
) | |
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: | |
klass = permanent and HttpResponsePermanentRedirect or HttpResponseRedirect | |
return klass(url % kwargs) | |
else: | |
return HttpResponseGone() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment