flask中for循环
(⼀)针对字典
html代码:
{% for k,v in user.items() %}
<p>{{k}}:{{v}}</p>
{% endfor %}`
python代码:
def fro():
user = {
'user': 'xxx',`
'age': 18
}
return render_template('fro.html', user=user)
(⼆)针对数组
html代码:
{% for k in user %}
<p>{{k}}</p>
{% endfor %}
pyhton代码:
def fro():
user=['1','2','3']
return render_template('fro.html', user=user
(三)传⼊数组⾥⾯含有字典的参数
html代码:
<table>
<thead>
<th>书名</th>
<th>作者</th>
<th>价格</th>
</thead>
<tbody>
{% for user in user %}
<tr>
<td>{{ user.name }}</td>
<td>{{user.author}}</td>
<td>{{ user.price }}</td>
</tr>
{% endfor %}
</tbody>
python代码:
def fro():
web=[
{'name':'西游记',
'author':'吴承恩',
'price':18
},
{'name': '西游记',
'author': '吴承恩',
'price': 18
}
]
return render_template('fro.html', user=web)

![[python] AES-GCM加解密函数-微慑信息网-VulSee.com](https://vulsee.com/wp-content/uploads/2024/12/4a3de68ff9eca0a01bae73a7470170f3.png)


![[python]文本处理-微慑信息网-VulSee.com](https://vulsee.com/wp-content/uploads/2023/12/e036ea90943d8195df3aa3e2ad3db122.png)
![[python] 输出颜色 - colorama / termcolor [补充]-微慑信息网-VulSee.com](https://vulsee.com/wp-content/uploads/2023/10/3ce37224d46fae3bee75b135ba129c77.png)
![[vulsee.com] 使用openpyxl 读取xlsx中的网址链接-微慑信息网-VulSee.com](https://vulsee.com/wp-content/uploads/2023/06/92d3798abeb4baabf03ebcf81d50e73e.png)


![[Google] Google Notebook昨天发布了-微慑信息网-VulSee.com](http://www.google.com/notebook/images/google_notebook.gif)






![[八卦] 王婷婷—揭秘一个大三女生的性爱录像-微慑信息网-VulSee.com](http://free.86hy.com/crack/pic/1.jpg)
![[随笔]今天国际警察节-微慑信息网-VulSee.com](http://photo.sohu.com/20041017/Img222528326.jpg)

青云网
