【发布时间】:2019-06-09 07:12:56
【问题描述】:
我只是想使用烧瓶在 html 中显示图像。但即使我给出了完整正确的图像路径,我也无法这样做。
我已经关注了这个链接
python flask display image on a html page
我的samply.py 是
import os
from flask import Flask, flash, request, redirect, url_for, render_template
app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
@app.route('/show_image')
def show_index():
full_filename = os.path.join(app.config['UPLOAD_FOLDER'], '2.jpg')
return render_template("layout.html", user_image = full_filename)
if __name__ == "__main__":
app.run(debug=True)
还有我的 HTML 代码:
<!DOCTYPE html>
<html>
<head>
<title>Index</title>
</head>
<body>
<img src="{{ user_image }}" alt="User Image">
</body>
</html>
我得到了
的输出127.0.0.1 - - [09/Jun/2019 11:50:41] "GET /home/user/Documents/images/2.jpg HTTP/1.1" 404 -
当我在我的 vscode 中点击此链接 /home/user/Documents/images/2.jpg 时,它正在显示正确的图像;这意味着路径有问题。
【问题讨论】:
标签: python-3.x flask