我正在使用Cheetah模板和Cherrypy,下面是我的主要python文件
Main.py:
def multiple(a,b):
return a*b
def index(self):
t = Template('template.tmpl')
#blah implementation here在我的模板文件中,我希望实现
<body>
<div>
$multiple(2,3)
</div>
</body>谁知道我怎样才能得到这个工具?非常感谢。
你好,安迪。
发布于 2011-05-10 21:04:06
t = Template("template.tmpl")
t.multiple = multiple这应该能起到作用。
发布于 2011-05-10 21:01:45
尝试使用searchList参数:
def index(self):
t = Template('template.tmpl', searchList=[multiple])它允许您定义您将能够在模板定义中使用的“占位符”。
发布于 2012-02-15 23:20:42
这可能会回答这个问题:
import Cheetah
import Cheetah.Template
def multiple(a,b):
return a*b
print Cheetah.Template.Template(file='template.tmpl',
searchList=[dict(multiple=multiple)])https://stackoverflow.com/questions/5950248
复制相似问题