对于Jinja2,在执行 for循环?在
Context = """
{% macro LopyLoop(PARSER) %}
{% for items in PARSER -%}
{{ items }}{% if not loop.last %},{% endif %}
{%- endfor %}
{% endmacro %}
{% set Mainlist = ['ABC','XYZ'] %}
{{ LopyLoop(Mainlist) }}
{{ LopyLoop(Mainlist[0]) }}
)
"""
Output = Template(Context)
print Output.render()
上述内容在使用[“ABC”,“XYZ”]时有效,但在使用字符串Mainlist[0]时无效
我找不到解决这个问题的方法
提前谢谢!在
环顾四周,我发现了这个链接 Looping over subset in Jinja
答案是 {{lopylop(Mainlist[0:1])}}
相关问题 更多 >
编程相关推荐