[Twisted-web] Using deferreds to render a page

Andrew Bennetts andrew-twisted at puzzling.org
Mon Dec 5 16:26:41 MST 2005

On Tue, Dec 06, 2005 at 04:16:05AM +1000, A. Goryunov wrote:
> I might be just dumb, but I can't figure out the correct way to do what 
> the following passage from Twisted.web's Howto suggests:
> "/Request a |Deferred|, return |server.NOT_DONE_YET|, and call 
> |request.write("stuff")| and |request.finish()| later, in a callback on 
> the |Deferred|/."
> How do I get at the request object from a callback function? All the 

You can pass extra arguments to callback functions.  So you can do e.g.:

    d.addCallback(callbackFunc, request)

And then define callbackFunc as:

    def callbackFunc(result, request):

Alternatively, as Grant suggests, you can use python's nested scopes to capture
the variable(s) you want.


More information about the Twisted-web mailing list