[英]How to correctly include javascript code in chameleon/zpt template (pyramid)?
[英]Is it possible to include pyramid modules in template file(in python code block)?
我使用.mako文件作為模板,我需要獲取有關當前會話的信息。 我應該怎么做? 我的想法是:在模板文件中的python代碼塊中導入會話工廠。 還有其他建議嗎?
將必要的會話信息傳遞給視圖中變量中的模板。
@view_config(renderer='foo.mak')
def my_view(request):
return {'mysession':request.session}
請求對象在MAKO模板上下文中可用。
您可以直接在模板中使用它。
例:
${request.session}
${request.session.get('SOME_VARIABLE')}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.