Home  >  Article  >  Backend Development  >  Pyramid Mako模板引入helper对象的步骤方法

Pyramid Mako模板引入helper对象的步骤方法

WBOY
WBOYOriginal
2016-06-06 11:28:191001browse

原理是我们在pyramind的before render event 中插入我们的helper

1. 创建helper.py文件,在里面添加上我们常用的方法

2. 在__init__.py文件中:

加入这个函数:

代码如下:


def add_renderer_globals(event):
    event['h'] = helpers



在main函数中

代码如下:


config.add_subscriber(add_renderer_globals, BeforeRender)



3. 在模板中使用定义的方法,h.method()
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn