如果我的asnitem.asn是,那么我想做X,这两个值都不是给出的值。
我认为有用的东西:
{%- if not asnitem.asn == 45102 or if not asnitem.asn == 24429 or if not asnitem.asn == 132203 %}
但这只是给了我一个语法错误。所以我也试过:
{%- (if not asnitem.asn == 45102) or (if not asnitem.asn == 24429) or (if not asnitem.asn == 132203) %}
但这也是行不通的。因此,我目前混淆了如何在 if状态中执行或Jinja2的多个状态。感谢每一个给出答案的人。另外,如果有更好的方法来做这样的事情,请告诉我。可能是什么?:
{%- if not asnitem.asn == 45102 || 24429 || 132203 %}
发布于 2019-11-13 14:22:04
在这种情况下,in
逻辑运算符应该会帮助您。试试看这个样本:
{%- if not asnitem.asn in [45102, 24429, 132203] %}
这里的in
操作符检查右侧列表([45102, 24429, 132203]
)中左手值(asnitem.asn
)的存在.not
反演检查结果。
https://stackoverflow.com/questions/58839131
复制相似问题