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

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 11:28:19
Original
1087 people have browsed it

原理是我们在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()
Related labels:
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template