【发布时间】:2011-08-29 20:29:49
【问题描述】:
mako 文档似乎暗示了在“使用块”之前能够拥有动态的可选布局,但我很难将它弄清楚。cle
people = dict_cursor.fetchall()
all_possible_cols = ('Name','Birth','Gender', 'Address','City','State', ...]
user_cols = user_wants(user_id) # ('State','Gender','Name')
template.render(**locals())
如何动态调用模板中的defs来渲染列?
魔子模板
% for person in people:
<tr>
% for col in user_cols:
How do I dynamically call the def/block?
% endfor
</tr>
% endfor
<%def name="Name()"> ... </%def>
<%def name="Birth()"> ... </%def>
<%def name="Gender()"> ... </%def>
<%def name="Address()"> ... </%def>
<%def name="City()"> ... </%def>
<%def name="State()"> ... </%def>
因此,一个用户可能想要 ('Name','Birth','Gender'),另一个用户 ('Gender','State', 'Birth'),而第三个用户可能希望它们以不同的顺序排列。如何在 mako 模板中完全支持此功能?
【问题讨论】:
标签: python templates dynamic mako