手机
当前位置:查字典教程网 >脚本专栏 >python >Pyramid Mako模板引入helper对象的步骤方法
Pyramid Mako模板引入helper对象的步骤方法
摘要:原理是我们在pyramind的beforerenderevent中插入我们的helper1.创建helper.py文件,在里面添加上我们常用...

原理是我们在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()

【Pyramid Mako模板引入helper对象的步骤方法】相关文章:

python去掉字符串中重复字符的方法

python 测试实现方法

Python去掉字符串中空格的方法

python paramiko实现ssh远程访问的方法

python调用shell的方法

Python中针对函数处理的特殊方法

Python下singleton模式的实现方法

Python生成随机数的方法

python回调函数的使用方法

Python 面向对象 成员的访问约束

精品推荐
分类导航