【发布时间】:2018-03-20 06:56:27
【问题描述】:
我想从数据库中获取图片名称并通过这段代码显示在 html 文件中
<img src="{{ url_for('static', filename='img/{{rows.infor_image}}') }}" style="width:50%; height:60%;">
但我不知道如何用正确的语法编写来显示要显示的图像
我尝试在 .py 文件中声明 image_name 但我不知道如何使用它
@app.route('/herbsinfo/<id>')
def landing_page(id):
cur = mysql.connection.cursor()
#Query
cur.execute('SELECT version()')
result = cur.execute("SELECT * FROM information where infor_id = %s",[id])
rows = cur.fetchone()
image_name = rows['infor_image']
if result > 0:
return render_template('herbsinfo.html', rows=rows,image_name=image_name)
或者我可以用其他方式显示图像
【问题讨论】: