This generic view does the same that 'django.views.generic.simple.redirect_to' does but supports request.GET parameters.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | from django.http import HttpResponseGone, HttpResponsePermanentRedirect,\
HttpResponseRedirect
def redirect_to(request, url, permanent=True, **kwargs):
if url is not None:
klass = permanent and HttpResponsePermanentRedirect or HttpResponseRedirect
url = url % kwargs
if request.GET:
url = '?'.join([url, request.META['QUERY_STRING']])
return klass(url)
return HttpResponseGone()
|
More like this
- Template tag - list punctuation for a list of items by shapiromatron 11 months, 1 week ago
- JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 11 months, 2 weeks ago
- Serializer factory with Django Rest Framework by julio 1 year, 6 months ago
- Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 7 months ago
- Help text hyperlinks by sa2812 1 year, 7 months ago
Comments
This is now supported in Django 1.3 out of the box.
#
Please login first before commenting.