This is a quick shortcut to redirect the user to a view. The main gain is avoiding having to type 'from django.core.urlresolvers import reverse' every time you want to do a redirect!
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
- Template tag - list punctuation for a list of items by shapiromatron 10 months, 2 weeks ago
- JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 10 months, 3 weeks ago
- Serializer factory with Django Rest Framework by julio 1 year, 5 months ago
- Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 6 months ago
- Help text hyperlinks by sa2812 1 year, 6 months ago
Comments
There's django.shortcuts.redirect in Django 1.2, which I recommend.
#
Please login first before commenting.