Question

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?

Was it helpful?

Solution

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')
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top