ここで提案されているパフォーマンス上の理由から、pr-compiled テンプレートの使用方法を研究しています。
hello.tmplテンプレートディレクトリで次のように編集します
#attr title = "This is my Template"
<html>
<head>
<title>\${title}</title>
</head>
<body>
Hello \${who}!
</body>
</html>
次に、発行cheetah-compile.exe .\hello.tmplして取得しますhello.py
別のpythonファイルrunner.pyには、次のものがあります。
#!/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()
しかし、結果は
<html>
<head>
<title>${title}</title>
</head>
<body>
Hello ${who}!
</body>
</html>
しばらくデバッグすると、次のことがわかりました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()
トランスが None のように見えるので、 に進みDummyTransactionます。ここで何を見逃しましたか? それを修正する方法について何か提案はありますか?