Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass Base64 image string from Flask Python code to HTML?

I have a Flask server and I want to render a base64 image in HTML page.

Flask Code:

new_image_string = base64.b64encode(buff.getvalue()).decode("utf-8")
return render_template('perspective_result.html', img_data=new_image_string)

HTML CODE:

<img src="data:image/jpeg;base64,+img_data" alt="img_data"  id="imgslot"/>

I am getting the below error from browser console:

GET data:image/jpeg;base64,+img_data 0 ()

Where did I go wrong?

like image 653
Jennings Avatar asked Mar 05 '26 07:03

Jennings


1 Answers

<img src="data:image/jpeg;base64,{{ img_data }}" alt="img_data" id="imgslot"/>

This is the way we can solve this.

like image 165
maodo Avatar answered Mar 07 '26 19:03

maodo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!