【发布时间】:2013-09-24 20:14:02
【问题描述】:
我在 Python 项目中使用 Mako 模板。
值 None 有时会用于联系人标题。如果值为None,我想隐藏None。
当前代码:
<td class="data-career request-row">
%if 'title' in message['contact'] and 'title' is not 'None':
${message['contact']['title']}
%endif
</td>
我也试过了:
%if 'title' in message['contact'] and 'title' is not None:
但是 None 仍然出现,所以我很好奇在 Mako 中检查传入字符串值的正确方法是什么?
我在他们的docs site 上找不到任何东西。
【问题讨论】:
-
%if message['contact'].get('title'):工作吗?