0

I have stored images in a sqlite class Blog, the columns are:

  • img: Binary image data
  • img_mimetype: Mime Type.
class Blog(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    img = db.Column(db.Text, nullable=False)
    img_mimetype = db.Column(db.Text, nullable=False)

How can I return the image itselft to insert it in an HTML template? I currently have this. but I cannot access the image itself.

@app.route('/')
def index():
    blog_posts = get_posts()
    return render_template('index.html', blog_posts=blog_posts)

def get_posts():
    posts = Blog.query.order_by(Blog.date_created).all()
    return posts

The goal is to have something like this:

{% for project in projects %}
   <img class="project-card-img" src="{{project.img}}"
{% endfor %}
Lalo Venegas
  • 48
  • 1
  • 4
  • You can save image in a folder and while saving it, you can pass it's name to database. Then read the image using name in database. – charchit Jun 11 '21 at 05:07

0 Answers0