Login

Generic view 'redirect_to' that supports QUERY_STRING

Author:
marinho
Posted:
October 6, 2009
Language:
Python
Version:
1.1
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. Auto upload_to path generator by junaidmgithub 6 hours, 27 minutes ago
  2. LazyPrimaryKeyRelatedField by LLyaudet 1 week ago
  3. CacheInDictManager by LLyaudet 1 week ago
  4. MYSQL Full Text Expression by Bidaya0 1 week, 1 day ago
  5. Custom model manager chaining (Python 3 re-write) by Spotted1270 2 weeks, 1 day ago

Comments

mlissner (on January 27, 2012):

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

#

Please login first before commenting.