【发布时间】:2021-07-25 17:13:26
【问题描述】:
我想将外部链接用作烧瓶中 HTML 中 img 标记中的图像。 我知道如何将图像保存在静态文件夹中,但我的情况不同。
我想在 index.html 中执行以下代码:
<body>
<h1>external image</h1>
<img src={{url_for('static',filename='https://unsplash.com/photos/uUVkzxDR1D0')}}
alt="No image">
</body>
我的 Flask 看起来像这样:
from flask import Flask,render_template
app=Flask(__name__,static_url_path='',static_folder='static',template_folder='templates')
@app.route("/")
def index():
return render_template("index.html")
我尝试从 url_for 函数中删除静态端点,因为在静态文件夹中搜索外部图像链接没有意义,但后来我得到了 url_for 需要端点的错误。所以,我不知道如何放图片链接。
一切正常。只有图像没有得到 渲染,我得到了替代文本,即屏幕上的“无图像”。
任何帮助将不胜感激。提前感谢您的帮助。
【问题讨论】:
标签: html python-3.x flask jinja2 web-deployment