models.py
我可以在这里存储数据
class AddNote(db.Model):
id = db.Column(db.Integer, primary_key=True)
title = db.Column(db.String(64), unique=True)
description = db.Column(db.String(120), unique=True)
img_name = db.Column(db.String(32))
img = db.Column(db.LargeBinary)
routes.py
从数据库中检索数据
@app.route('/')
def index():
notes = AddNote.query.all()
return render_template('index.html', title='NoteBook', notes=notes)
HTML 模板
如何在img标签中显示图片
{% for note in notes %}
<img src="" class="card-img-top">
{% endfor %}
答案 0 :(得分:0)
好吧,如果数据库图像是静态存储的,那么应该做一个简单的静态请求
<img src="{{ url_for('static',filename='{{note.img_name}}') }}"></img>