On Jul 22, 2:17 am, Wyatt Baldwin <[email protected]> wrote: > On Jul 21, 5:56 am, huydo <[email protected]> wrote: > > > > > Hi, > > > Just trying to do a direct from the __call__ method in my base.py file > > and this is the following exception which I am getting. > > > redirect(url(controller='redirect', action='index')) > > File 'c:\\apps\\xbits\\ktrack\\python\\lib\\site-packages\\pylons-1.0- > > py2.5.egg\\pylons\\controllers\\util.py', line 208 in redirect > > raise exc(location=url).exception > > HTTPFound: 302 Found > > Content-Type: text/html; charset=UTF-8 > > Content-Length: 0 > > Location: /redirect/index > > > Adding the following line to my middleware.py file (just after the > > #CUSTOM MIDDLE HERE) fixed it. > > > app = httpexceptions.make_middleware(app) > > > Is this a bug ? or am I doing something wrong ? > > I'd say it's more that you're doing something wrong. ;) redirect works > by raising an exception (the one you're seeing). Normally, this would > be caught by the base WSGIController class (in _inspect_call) and > converted into an HTTP response, but because __call__ is a setup > function and not part of the "action context", the exception isn't > caught, presumably by design. > > In other words, you should only use redirect from within the "action > context"--either in __before__, a particular action method, or > __after__. If you really want to redirect from __call__, you can > create an instance of HTTPFound and return that from __call__.
Hi Wyatt, Thanks for the pointer. It does appear redirecting in __call__ does not work. I have moved all my logic which was in __call__ to __before__ and redirect works in there. It would be nice to be able to return a response in __before__ as well rather then only be allowed to raise an exception. Cheers and thanks again. Huy -- You received this message because you are subscribed to the Google Groups "pylons-discuss" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en.
