我的目标是使用Flask在网站上显示图像。
图像在以下位置:
/static/img/articles镜像名称为:"43.jpg“
硬编码它工作得很好:
<img src="{{ url_for('static', filename='img/articles/43.jpg') }}" alt="no picture">然而,我需要路径是动态的(图像是今天的43,也许明天的17和后天的58 )。
我尝试了所有方法,例如:
last_id_jpg =r“img/文章/43.jpg”
return render_template("index3.html",
last_id_jpg = last_id_jpg
)通过以下方式:
<img src="{{ url_for('static', filename=last_id_jpg) }}" alt="no picture">或者:
<img src="{{ url_for('static', filename='last_id_jpg') }}" alt="no picture">但是找不到设计图片的路径(网页显示“无图片”)。我做了一些研究和everything seems OK
我的代码出了什么问题?
发布于 2020-08-10 16:16:44
你的last_id_jpg上有一个打字错误。它应该是
last_id_jpg = r"img/articles/43.jpg" # article with s不
last_id_jpg = r"img/article/43.jpg"https://stackoverflow.com/questions/63335678
复制相似问题