Login

Generic view 'redirect_to' that supports QUERY_STRING

Author:
marinho
Posted:
October 6, 2009
Language:
Python
Version:
1.1
Tags:
http view generic redirect_to
Score:
0 (after 0 ratings)

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

  1. login_required for a generic view in URLconf by pgugged 7 years, 2 months ago
  2. Generic Views for newforms by jnievas 7 years, 7 months ago
  3. ajax form handler generic view by amitu 6 years, 10 months ago
  4. Persistent Params Decorator by achimnol 6 years, 1 month ago
  5. django-constance generic view by skam 6 months, 3 weeks ago

Comments

mlissner (on January 27, 2012):

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

#

Please login first before commenting.