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__.

-- 
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.

Reply via email to