Doing redirect without request

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
class Redirect(Exception):
    def __init__(self, url):
        self.url = url

# where request is not:

raise Redirect(reverse('someurl'))

# redirect handler, where request is:

from django.http import HttpResponseRedirect
try:
    return something(request, ...)
except Redirect, r:
    return HttpResponseRedirect(r.url)

More like this

  1. Redirect with change list with filters intact with admin actions by AndrewIngram 3 years, 10 months ago
  2. Simple Exception Response for AJAX debugging by newmaniese 5 years, 2 months ago
  3. Quick script to convert json data to csv by stephenemslie 3 years ago
  4. Message exception by marinho 4 years, 7 months ago
  5. Middleware to prevent access to the admin when user ip not in INTERNAL_IPS by jezdez 2 years, 10 months ago

Comments

(Forgotten your password?)