[Twisted-web] HTTP redirection from data_*/render_* methods

en.karpachov at ospaz.ru en.karpachov at ospaz.ru
Fri Jul 15 09:58:38 MDT 2005


On Fri, Jul 15, 2005 at 07:40:33AM -0600, Samuel Reynolds wrote:
> At 2005-07-15 02:46 PM +0400, you wrote:
> >I wondered if I can make an HTTP redirection (302) from inside of render_*
> >or data_* method. Here is a code snipped I wrote; I'd like to know if it
> >can be considered as "good" nevow practice?
> 
> What about
>     request.redirect( redirectUrl )
> possibly followed by
>     request.finish()

That is, this method doesn't allow to return an empty body. If it is ok to
return fully rendered page together with the "302 Found", then it is
probably enough to call request.redirect, that's right.

So the render method from my snippet should probably look like

def render_redirect(self, url):
     def _(ctx, data):
          inevow.IRequest.redirect(str(url))
          return "Redirecting"
     return _

Thanks for your hint.

-- 
jk



More information about the Twisted-web mailing list