欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Pyramid Mako模板引入helper對象的步驟方法

 更新時間:2013年11月27日 11:50:15   作者:  
ylons中的mako模板,默認(rèn)會引入一個helper對象,我們可以在里面擴(kuò)展方法,應(yīng)對在模板輸出時候會常用的操作,那么在Pyramid中如何默認(rèn)引入同樣的輔助類到模板中

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

1. 創(chuàng)建helper.py文件,在里面添加上我們常用的方法

2. 在__init__.py文件中:

加入這個函數(shù):

復(fù)制代碼 代碼如下:

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


在main函數(shù)中
復(fù)制代碼 代碼如下:

config.add_subscriber(add_renderer_globals, BeforeRender)


3. 在模板中使用定義的方法,h.method()

相關(guān)文章

最新評論