0
由於性能原因建議here,我正在研究如何使用pr編譯模板。獵豹預編譯模板使用
我在模板目錄編輯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()
它看起來像反式是無,所以它去DummyTransaction
,我錯過了什麼嗎? 有關如何解決它的任何建議?