Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 变色龙模板渲染_Python_Templates_Chameleon - Fatal编程技术网

Python 变色龙模板渲染

Python 变色龙模板渲染,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(

我是新的变色龙模板。我粘贴代码片段

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(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:在模板中添加更多插槽,并在调用模板时将其作为关键字参数传入。