morepath的变色龙模板集成
more.chameleon的Python项目详细描述
more.chameleon:morepath的chameleon模板集成
more.chameleon是添加zope页的Morepath的扩展 模板(zpt)支持.pt扩展,使用Chameleon 模板引擎。
有关zpt模板语言的详细信息,请参见Chameleon language reference。
示例用法:
from more.chameleon import ChameleonApp class App(ChameleonApp): pass @App.path(path='persons/{name}') class Person(object): def __init__(self, name): self.name = name @App.template_directory() def get_template_directory(): return 'templates' @App.html(model=Person, template='person.pt') def person_default(self, request): return {'name': self.name}
然后在person.pt(在templates子目录中):
<html> <body> <p>Hello ${name}!</p> </body> </html>
在开发过程中,让变色龙重新加载模板是有帮助的。 更改后自动执行。要启用此功能,请使用 MOREPATH_TEMPLATE_AUTO_RELOAD环境变量。
您可以为您的流程启用它:
MOREPATH_TEMPLATE_AUTO_RELOAD=1 python run.py
或者你的贝壳:
export MOREPATH_TEMPLATE_AUTO_RELOAD=1 python run.py
要进一步控制变色龙渲染,可以定义chameleon设置 你的应用程序中的部分。例如,你如何打开变色龙的 debug功能:
@App.setting_section(section='chameleon') def get_setting_section(): return {'debug': True}
有关变色龙配置选项的详细信息,请参阅 Chameleon API reference中的配置关键字参数。
变化
0.2(2016-01-23)
现在可以使用MOREPATH_TEMPLATE_AUTO_RELOAD环境变量 以控制变色龙的自动重新加载行为。
有关详细信息,请参见readme.rst。
0.1(2015-04-09)
- 首次公开发行。