gpt4 book ai didi

python - Jinja 模板字典/列表过滤器 "contains"或 "like"- Saltstack

转载 作者:行者123 更新时间:2023-11-30 22:32:05 25 4
gpt4 key购买 nike

我想过滤包含“foo_”或以“foo_”开头的值,并忽略列表中的其他值。

值(无法修改):

TEST:
- foo_a
- foo_b
- bar_a
- bar_b
- test_c

模板:

{% for value in grains['TEST'] %}
- do something with value that contains "foo_"
{% endfor %}

我该怎么做?

我尝试过:

{% for value in grains['TEST']|map(^foo_) %}
- do something with value that contains "foo_"
{% endfor %}

=> 没有成功

最佳答案

假设每个值都是一个字符串(似乎是这样),您应该能够使用字符串的标准 startswith 方法,例如 {% if value.startswith(' foo_') %}

关于python - Jinja 模板字典/列表过滤器 "contains"或 "like"- Saltstack,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45617258/

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