下面是一些我在Pyramid中用于将宏加载到变色龙模板中的代码:
@subscriber(BeforeRender)
def add_base_templates(event):
"""Define the base templates."""
main_template = get_renderer('../templates/restaurant.pt').implementation()
event.update({ 'main_template': main_template })
没有金字塔,我怎么能达到同样的效果?例如,在本代码中:
^{pr2}$
让我们来看看您的代码是做什么的;要在金字塔之外使用宏,您所要做的就是复制它。在
当您在金字塔中调用
.implementation()
时,实际上是在检索一个加载了正确模板路径的PageTemplateFile
实例。BeforeRender
事件允许您从视图修改dict响应,并在add_base_templates
事件处理程序中添加一个名为main_template
的新条目。在您自己的代码中组合这两种方法以获得相同的效果,在调用您的
lizard
模板时传递一个main_template
宏模板:真的,就这些了。在
相关问题 更多 >
编程相关推荐