0
我使用金字塔1.3與Mako模板。我有一個名爲「create」的方法,它將一個空字典返回給模板。我打算爲創建和編輯使用相同的「create.mako」模板。我已經把像這樣的上下文變量在我的輸入字段:UNDEFINED mako模板錯誤
<input type="text" id="nameInput" value="${content['name']}" />
的問題,這是我得到像下面的錯誤,當我嘗試加載創建方法:
<input id="nameInput" value="${content['name']}" type="text" class="span8" style="background-color: #EED3D7;" />
TypeError: 'Undefined' object is unsubscriptable
這是當然,這是正確的,因爲create方法只返回一個空字典,所以沒有鍵「content」。這在以前的塔0.9.7中很好;如果它不存在,它將只是一個空字符串。
我發現從StackOverflow的一個解決方案:
import mako.runtime
mako.runtime.UNDEFINED = ''
但是,在我把這個在我的金字塔計劃?