我的静态目录中有一个结果文件夹,其中包含九张名为“result_1.jpg”到“result_9.jpg”的图像,我想在我的 html 页面的网格中以正确的顺序显示它们。
一切正常,除了输出顺序完全随机但始终相同。
这是我的python片段:
@app.route('/fResults/')
def show_fResults():
imgs = os.listdir('static/results/')
imgs = ['results/' + file for file in imgs]
return render_template('fResults.html',imgs = imgs)
这是我的 html 片段:
<div class="resultGrid">
{% for img in imgs %}
<div class="resultImages">
<img id="results" src="{{ url_for('static',filename = img) }}" alt="{{loop.index}}">
</div>
{% endfor %}
</div>
这里是 html 输出:
有没有办法强制它使用给定的顺序?
先谢谢你!
编辑:多亏了 Epsi95,我才能够解决我的问题。
@Epsi95 非常感谢!