HttpResponseRedirectView - Redirect to a view

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
from django.http import HttpResponseRedirect
from django.core.urlresolvers import reverse

class HttpResponseRedirectView(HttpResponseRedirect):
    """
        This response directs to a view by reversing the url
    
        e.g. return HttpResponseRedirectView('org.myself.views.myview') 
        or use the view object e.g.
             from org.myself.views import myview
             return HttpResponseRedirectView(myview)
        
        You can also pass the url arguments to the constructor e.g.
        return HttpResponseRedirectView('org.myself.views.myview', year=2008, colour='orange')
    """
    def __init__(self, view, *args, **kwargs):
        viewurl = reverse(view, args=args, kwargs=kwargs)
        HttpResponseRedirect.__init__(self, viewurl)

More like this

  1. View Redirect Decorators by bryanpieper 3 years, 9 months ago
  2. Internet Explorer Redirect Decorator by johnboxall 5 years, 6 months ago
  3. Redirect view based on GEO by jorjun 4 years, 8 months ago
  4. login_required decorator that doesn't redirect by brutasse 3 years, 2 months ago
  5. Neat one off redirect by adamlofts 5 years, 7 months ago

Comments

km0r3 (on October 29, 2010):

There's django.shortcuts.redirect in Django 1.2, which I recommend.

#

(Forgotten your password?)