0
我們正試圖想出一種在jinja2中使用事實的方法For循環。Jinja2中的變量For循環
例如,我想要獲取屬於我的memcached組的所有服務器以及基於發佈的組(如tag_release_dev
或tag_release_prod
)。當我嘗試在For循環中使用{{ tt_release }}
時,它將評估{{ tt_release }}
而不是變量的值。有沒有辦法在循環定義中使用變量?
{% for host in groups["tag_function_mem"] | intersect(groups["tag_release_{{ tt_release }}"]) %}
{{ host }}:11211
{%- if not loop.last %},{% endif %}
{%- if loop.last %}"{% endif %}
{% endfor %}
{% endif %}
太好了,謝謝你的解釋! – tweeks200