原理是我們?cè)趐yramind的before render event 中插入我們的helper
1. 創(chuàng)建helper.py文件,在里面添加上我們常用的方法
2. 在__init__.py文件中:
加入這個(gè)函數(shù):
代碼如下:
def add_renderer_globals(event):
event['h'] = helpers
在main函數(shù)中
代碼如下:
config.add_subscriber(add_renderer_globals, BeforeRender)
3. 在模板中使用定義的方法,h.method()
新聞熱點(diǎn)
疑難解答
圖片精選