Re: Deferred 101

<[email protected]>
Newsgroups gmane.comp.python.twisted.web
Message-ID <[email protected]>
----- Mensaje original -----
De: Phil Mayers <[email protected]>
Fecha: Martes, Julio 5, 2011 4:01 am
Asunto: Re: [Twisted-web] Deferred 101

> On 07/05/2011 05:14 AM, [email protected] wrote:
> > Hi guys,
> >   I'm totally new to Twisted although everything I try so far has been a lot of
> > fun. I have a really simple situation it seems I cannot wrap my head around.
> > Although the tutorial have been really helpful I cannof find how to fix this
> > last part.
> >
> 
> The problem is almost certainly that Mako is not deferred-aware. If 
> it 
> were, it would stop the render when encountering a deferred and re-
> start 
> when the deferred callback runs. But if it were, the return value 
> of 
> it's render method would almost certainly itself be a deferred, 
> which of 
> course it's not.
> 
> Try something this:
> 
> def render_POST(self, request):
>   d = myDeferredMethod()
>   def render(value):
>     request.write(template.render(...., value=value))
>     request.finish()
>   d.addCallback(render)
>   return NOT_DONE_YET
> 
> i.e. add a callback to the deferred which does the rendering for 
> you 
> only when the result is available.
> 
> FWIF the recently added twisted.web.template handles deferred 
> natively.
>

Thanks a lot Phil. That fixed my problem.

Eduardo Miguez
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.