[英]Python, Pyramid, Chameleon : parse Chameleon template in string
I have a Chameleon template stored as a string. 我有一个Chameleon模板存储为字符串。 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 : 根据api文档 ,似乎是这样:
from chameleon import PageTemplate
t = PageTemplate('some string template')
rendered_content = t.render(encoding='utf-8')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.