0

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?

Alessandro Minoccheri
  • 35,521
  • 22
  • 122
  • 171
Nikhil Rupanawar
  • 4,061
  • 10
  • 35
  • 51

1 Answers1

2

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')
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343