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?

有帮助吗?

解决方案

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')
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top