【问题标题】:Flask access json data and embedding it in a <img> tag [duplicate]Flask 访问 json 数据并将其嵌入到 <img> 标签中[重复]
【发布时间】:2021-06-03 15:49:23
【问题描述】:

我有以下烧瓶路线

@app.route("/rec_demo")
def rec_demo():
    print("de lokos")
    response_data = {"rec_one": "pic_trulli.jpg"}

    return render_template("demografico.html", data=response_data)

我尝试访问 rec_one 以将其显示为图像

<div id='info_section'>
        <img src={{ data.rec_one }} alt="Girl in a jacket" width="500" height="600">
</div>

但是当我在实时服务器上检查网络时,src 无法解析为我传递的 url。如果我有

<div id='info_section'>
        {{ data.rec_one }}
</div>

我可以在我的网页中看到 url 值作为文本

【问题讨论】:

    标签: python html flask web


    【解决方案1】:

    你应该在你的 flask 调用周围加上引号 -- IE

    <img src="{{ data.rec_one }}" alt="Girl in a jacket" width="500" height="600">
    

    这不仅会导致flask 输出出现问题。浏览器的解释也会出现问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-10-25
      • 1970-01-01
      • 1970-01-01
      • 2014-06-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多