[Twisted-Python] Deferred support in DOMTemplate

Donovan Preston dp at twistedmatrix.com
Fri May 10 23:29:46 MDT 2002


Hello everyone

A while back glyph suggested I add Deferred support to DOMTemplate. If a 
specific node handler wanted to defer it's return value, it would create 
a deferred and return it. He also requested a simple example of using 
it. I thought it might be interesting to more people than just glyph, so 
here it is.

This will only work with the latest CVS.

I might explain a couple of things while I am at it:

DOMTemplate is an HTML templating system that uses the DOM (Document 
Object Model) to give Python code an interface for manipulating an HTML 
template. Basically, you register your interest in tags containing 
certain attributes, like a particular class, id, or tag name. Then, 
DOMTemplate crawls the dom looking for matching tags. When one is found, 
your callback is called with an instance of xml.dom.minidom.Node, and 
you are able to create new nodes, move, copy nodes, and delete them. 
Thus, all of the repeat logic is implemented in Python, and no 
templating logic is in the HTML at all -- merely attributes on tags that 
hook them up with Python methods.

An rpy is a Resource-generating python file. If you place an rpy in a 
twisted.web.static tree, the rpy handler will execute the file and look 
in the resulting namespace for an item named "resource". This gives you 
a quick and easy way to deploy new applications into an already-running 
web server. It is also great for debugging, because the file will be 
reloaded each time you hit it.

Hope this is enlightening!

Donovan

-------------- next part --------------
A non-text attachment was scrubbed...
Name: DeferredUsingPage.rpy
Type: application/applefile
Size: 475 bytes
Desc: not available
URL: </pipermail/twisted-python/attachments/20020510/ce283116/attachment-0004.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: DeferredUsingPage.rpy
Type: application/text
Size: 911 bytes
Desc: not available
URL: </pipermail/twisted-python/attachments/20020510/ce283116/attachment-0005.bin>


More information about the Twisted-Python mailing list