[Twisted-web] Can't subclass when docFactory is a loaders.stan instance.

Donovan Preston dp at ulaluma.com
Thu Sep 9 15:30:03 MDT 2004

On Sep 9, 2004, at 3:06 PM, Patrick B. Day wrote:

> Is there anyway when constructing a page using stan to use render_*
> methods which are defined in the subclass?

The same way the HTML templates cause an invocation of a render_* 
method -- by setting the render special on a Tag to a directive. Sorry 
it's not better documented:

class Foo(Page):
     docFactory = rend.stan(tags.html[

class Bar(Foo):
     def render_title(self, ctx, data): return ctx.tag["Hello Title"]
     def render_header(self, ctx, data): return ctx.tag["Hello Header"]
     def render_body(self, ctx, data): return ctx.tag["Hello Body"]

By the way, this is a perfect example of where you would want to use 
the macro special, when it is implemented. Page would have to have a 
metaclass that cloned and compiled a unique copy of the superclass' 
docFactory, but after that all the non-dynamic nodes (nodes without a 
render method) would be optimized into contiguous string runs. As it is 
now, the render methods run every time the page is hit, which isn't too 
big of a deal but is slightly slower.


More information about the Twisted-web mailing list