作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 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:
但是仍然没有出现,所以我很好奇 Mako 中检查传入字符串值的正确方法是什么?
我在他们的 docs site 上找不到任何内容.
最佳答案
显然字符串'title'
不能是None
,因为它是......好吧,'title'
。 :D
%if 'title' in message['contact'] and message['contact']['title'] is not None:
${message['contact']['title']}
%endif
或
%if 'title' in message['contact']:
${message['contact']['title'] or ''}
%endif
或者最简单/最短
${message['contact'].get('title', None) or ''}
关于Python - Mako 模板 : How to check for incoming string?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18991194/
我是一名优秀的程序员,十分优秀!