手机
当前位置:查字典教程网 >脚本专栏 >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 paramiko实现ssh远程访问的方法

python调用shell的方法

Python下singleton模式的实现方法

Python中os和shutil模块实用方法集锦

python实现问号表达式(?)的方法

pyramid配置session的方法教程

Pyramid将models.py文件的内容分布到多个文件的方法

盘点提高 Python 代码效率的方法

Python生成随机数的方法

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

精品推荐
分类导航