【发布时间】:2020-10-29 21:24:16
【问题描述】:
我正在尝试以一种可以访问某些图像的方式制作网页,这些图像保存在“静态/图像”文件夹中,通过嵌入在它们各自名称下的超链接。我尝试在这样的页面中嵌入一个链接,但该网页有一个非常小的图标,没有显示图像。
<!DOCTYPE html>
<html>
<body>
<a href="/goto/Koala.png"> go </a>
</body>
</html>
from flask import Flask, render_template, session, redirect, request, url_for
import pandas as pd
import os
IMG_FOLDER = os.path.join('static', 'images')
app = Flask(__name__)
app.config['IMG_FOLDER'] = IMG_FOLDER
@app.route('/',methods=["GET"])
def homePage():
return render_template("index.html")
@app.route('/')
@app.route('/goto/<name>')
def show_index(name):
file = name
full_filename = os.path.join(app.config['IMG_FOLDER'], file)
return render_template("goto.html", user_image = full_filename)
if __name__ == "__main__":
app.run(debug=True)
<!DOCTYPE html>
<html>
<body>
<img src="{{ user_image }}" alt="User Image">
</body>
</html>
相反,当我以下列方式使用它时,它显示得很好 -
from flask import Flask, render_template, session, redirect, request, url_for
import pandas as pd
import os
IMG_FOLDER = os.path.join('static', 'images')
app = Flask(__name__)
app.config['IMG_FOLDER'] = IMG_FOLDER
@app.route('/',methods=["GET"])
def homePage():
return "hello"
@app.route('/')
@app.route('/goto')
def show_index():
file = 'Koala.png'
full_filename = os.path.join(app.config['IMG_FOLDER'], file)
return render_template("goto.html", user_image = full_filename)
if __name__ == "__main__":
app.run(debug=True)
我可能在某处做错了什么。任何帮助将非常感激。我正在尝试将这些名称以 for 循环的形式嵌入数据框中。无论如何,提前谢谢!
【问题讨论】: