[Twisted-web] about macro and render

Manlio Perillo manlio_perillo at libero.it
Wed Feb 21 05:32:08 CST 2007


Hi.

I want to compose a page, using a main template.
A simple solution is to use macros

class Resource(rend.rend):
   def macro_main(self, ctx):
      return loaders.xmlfile(...)


The macro_main method is called only once.

However it seems that macros are going to be removed, moreover if I 
change the child template, I have to reload the server.

A solution is to use a render (code not tested):

class Resource(rend.rend):
   template = ... # The child template to load

   def macro_main(self, ctx):
      return self.state.setdefault(
               template, loaders.xmlfile(self.template)
               )


Here I'm storing the loader instance in a dictionary, to optimize 
template loading.


Is this solution as efficient as the one with macros?



Thanks Manlio Perillo



More information about the Twisted-web mailing list