Genshi in Nevow, Revisited
Posted on March 27, 2008 by oubiwann

About a year ago, I blogged about usi ng Genshi in Nevow. It was purely an exercise in curiosity on my part: I wanted to know how flexible Nevow's template parsing was. Could I just drop something else in there that was completely different? The answer was yes and no :-)
The "no" part of that was discovered by a kind reader, Karl Bartel, who found that the Genshi templates in Nevow were one-time wonders: after the first render, data was not refreshed. I didn't have time to take a look at why, since Zenoss was occupying so much of my time then. Now that I'm rocking out at Divmod, this sort of thing is more or less my business now :-) What's more, a friend recently made a deeply heart-felt plea to get Genshi working on Nevow, so I took another look tonight.
Here's the "yes" part of that answer :-) This only represents about an hour or so of work, so this hasn't been tested very thoroughly, but there's a trivial way to get last year's old, static code working such that Genshi templates are dynamically rendered in Nevow. Here's what I did to make it work:
- preserve the original template data in a temp variable
- reassign to self.template after Nevow's load() method has been called
- clean Nevow's template cache
If you want a single template to be able to be processed by both Nevow's templating machinery as well as Genshi's, you're going to have to make some sacrifices in efficiency. However, if you want a pure-Genshi solution for Nevow, you should be able to use this code to get something up in no time.
In addition to the bullet points above, I also did the following:
- added some "method filters" so that Nevow stuff didn't get called by the Genshi loader
- checked to see if the python attributes available to the Genshi templates were callable and if so, called them
Technorati Tags: community, genshi, howto, python, software, templating, twisted, web