Python 变色龙模板渲染
我是新的变色龙模板。我粘贴代码片段 runtemp.pyPython 变色龙模板渲染,python,templates,chameleon,Python,Templates,Chameleon,我是新的变色龙模板。我粘贴代码片段 runtemp.py import os path = os.path.dirname(__file__) from chameleon import PageTemplateLoader templates = PageTemplateLoader(os.path.join(path, "templates")) template = templates['mytemp.pt'] template(name='John') print str(
import os
path = os.path.dirname(__file__)
from chameleon import PageTemplateLoader
templates = PageTemplateLoader(os.path.join(path, "templates"))
template = templates['mytemp.pt']
template(name='John')
print str(template.read())
mytem.pt
<testtag>
<innertesttag>${name}</innertesttag>
</testtag>
${name}
但我得到的结果是
<testtag>
<innertesttag>${name}</innertesttag>
</testtag>
${name}
我期望输出中的是John,而不是od$(名称)出什么事了?如何渲染模板
template.read()
只读取模板的内容;您放弃了实际的渲染结果<代码>模板(name='John')返回渲染
改为这样做:
print template(name='John')
但是如何对多个值执行此操作?如姓名、地址、电话等@user1539813:在模板中添加更多插槽,并在调用模板时将其作为关键字参数传入。