[Twisted-Python] Twisted.web/DOMTemplate

Donovan Preston dp at twistedmatrix.com
Sun Aug 11 05:39:30 EDT 2002


On Saturday, August 10, 2002, at 05:54 AM, Stephen Thorne wrote:

> Okay, I've been doing some hacking trying to make a small application 
> using
> twisted.web and the .rpy stuff, using DOMTemplate.

Awesome. I really appreciate people using it and providing feedback; 
designing in a vacuum is tough.

[ snip ]

> This (when twistd --nodaemon is used) prints 1 twice (instead of the 
> once
> expected).

[ snip ]

> This is *bad*. viewMethod in this instance is 
> response.factory_getBody, and in
> order to figure out if factory_getBody returns a widget as opposed to 
> an
> instance of xml.dom.minidom.Element it actually calls the function to 
> have a
> look. If it doesn't return a widget it *throws the result away*. 
> viewMethod
> is then returned and used elsewhere, where its actually intended to be 
> used.

Indeed it is bad. The fix was to return the result up if the result was 
*not* a widget, and not bother calling viewMethod again. Since I always 
program DOMTemplate using domwidgets nowadays, I never encountered this.

Patch committed, which you already know since you committed the patch 
;-)

> Considering that rendering a template node could have program logic in 
> it that
> only should be evaluated once per pageview. It could also carry some
> expensive database transactions.

Just fyi,it is possible to do this sort of setup by overriding the 
setUp method. However, there are often cases where doing a monolithic 
"setUp" doesn't make sense, and leaving each node to gather it's own 
data is lazier and therefore more efficient.

Thanks for the bug report.
Donovan





More information about the Twisted-Python mailing list