I am new to chameleon templates. i paste code snippet ..

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>

But the output i got is

 <testtag>
       <innertesttag>${name}</innertesttag>
 </testtag>

I was expectinng John in output instead od $(name)
What is going wrong ? how to render template?

有帮助吗?

解决方案

template.read() just reads the contents of the template; you discarded the actual rendering result. template(name='John') returns the rendering.

Do this instead:

print template(name='John')
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top