Question

I have a Chameleon template stored as a string. I've got it in this form, because I need to do my own processing first. Following that, I want to parse the template, possibly using 'render to response':

render_to_response('templates/foo.pt',
        {'foo':1, 'bar':2},
        request=request)

However, I can't figure out how to parse a template stored in a string, rather than pointing to one in a file. Is this possible?

Was it helpful?

Solution

However, I can't figure out how to parse a template stored in a string, rather than pointing to one in a file. Is this possible?

It seems so, according to the api documentation:

from chameleon import PageTemplate

t = PageTemplate('some string template')
rendered_content = t.render(encoding='utf-8')
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top