我正在尝试以静态(静态/绘图)显示特定目录中的所有图像。这是我的蟒蛇:
hists = os.listdir('static/plots')
hists = ['plots/' + file for file in hists]
return render_template('report.html', hists = hists)
Run Code Online (Sandbox Code Playgroud)
和我的 html:
<!DOCTYPE=html>
<html>
<head>
<title>
Store Report
</title>
</head>
<body>
{{first_event}} to {{second_event}}
{% for hist in hists %}
<img src="{{url_for('static', filename='{{hist}}')}}" alt="{{hist}}">
{% endfor %}
</body>
</html>`
Run Code Online (Sandbox Code Playgroud)
当模板成功渲染时,不会获取模板。在新选项卡中打开图像会产生:
http://127.0.0.1:8080/static/%7B%7Bhist%7D%7D
我想问题出在这条线上,但我不知道什么是正确的:
<img src="{{url_for('static', filename='{{hist}}')}}" alt="{{hist}}">
尝试将行更改为:
<img src="{{url_for('static', filename=hist)}}" alt="{{hist}}">
Run Code Online (Sandbox Code Playgroud)
你在那里有一组额外的{{ }},它渲染为%7B和%7D。
| 归档时间: |
|
| 查看次数: |
7985 次 |
| 最近记录: |