Encoding binary data in flask/jinja2 Encoding binary data in flask/jinja2 flask flask

Encoding binary data in flask/jinja2


data:image/png;base64, says that the PNG data is base64 encoded, so I think that you need to base64 encode the image data before rendering the template. If you do that, the encoding error should go away. Something like this should do the trick:

@app.route('/recipe/<id>', methods=['GET', 'POST'])def show_entry(id):  entry = db_session.query(Recipe).get(id)  entry.image = entry.image.encode('base64')  return render_template('show_entry.html', entry=entry)

I'm not overly familiar with this, it could be a dict lookup?, i.e.

entry['image'] = entry['image'].encode('base64')