gpt4 book ai didi

Python - Mako 模板 : How to check for incoming string?

转载 作者:行者123 更新时间:2023-12-01 05:36:11 24 4
gpt4 key购买 nike

我在 Python 项目中使用 Mako 模板。

联系人头衔有时会出现值“None”。如果值为 None,我想隐藏 None

enter image description here

当前代码:

<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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com