Generic view 'redirect_to' that supports QUERY_STRING

 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

  1. Effective content caching for mass-load site using redirect feature by nnseva 1 year, 10 months ago
  2. Generic object_detail view filterable by multiple url values by jlorich 2 years ago
  3. Yet another query string template tag by atms 2 years, 1 month ago
  4. Persistent Params Decorator by achimnol 3 years, 9 months ago
  5. Add GET parameters from current request by naktinis 2 years ago

Comments

mlissner (on January 27, 2012):

This is now supported in Django 1.3 out of the box.

#

(Forgotten your password?)