Jinja2 - How to loop a json list?

后端 未结 2 1790
走了就别回头了
走了就别回头了 2021-02-03 10:41

How can I loop a json list with jinja2?

I have this json list,

[
    {
        \"first_name\": \"John\",
        \"last_name\": \"Smith\",
        \"user         


        
2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-03 11:07

    simple json iteration in jinja2

    
           {% for key in users[0] %}
           
           {% endfor %}
       
    
       {% for user in users %}
       
           {% for key in user %}
           
           {% endfor %}
       
       {% endfor %}
    
    {{ key }}
    {{ user[key] }}

提交回复
热议问题