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')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.