Cheetah pre-compiled template usage quesion

Posted by leo on Stack Overflow See other posts from Stack Overflow or by leo
Published on 2010-03-31T03:30:13Z Indexed on 2010/03/31 3:33 UTC
Read the original article Hit count: 436

Filed under:
|
|

For performance reason as suggested here, I am studying how to used the pr-compiled template.

I edit hello.tmpl in template directory as

#attr title = "This is my Template"

\${title} Hello \${who}!

then issued cheetah-compile.exe .\hello.tmpl and get the hello.py

In another python file runner.py , i have

!/usr/bin/env python

from Cheetah.Template import Template from template import hello def myMethod(): tmpl = hello.hello(searchList=[{'who' : 'world'}]) results = tmpl.respond() print tmpl

if name == 'main': myMethod()

But the outcome is

${title} Hello ${who}!

Debugging for a while, i found that inside hello.py

def respond(self, trans=None):



    ## CHEETAH: main method generated for this template
    if (not trans and not self._CHEETAH__isBuffering and not callable(self.transaction)):
        trans = self.transaction # is None unless self.awake() was called
    if not trans:
        trans = DummyTransaction()

it looks like the trans is None, so it goes to DummyTransaction, what did I miss here? Any suggestions to how to fix it?

© Stack Overflow or respective owner

Related posts about python

Related posts about cheetah