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

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


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

This is the way we can solve this.


1.First Add A empty Image Tag Without A Source

2.Then With Javascript preprocess the base64 data string

3.update the Image src with updated base64 data

<img src="" id="img" alt="Chart" height="100" width="100"><script>    data = "{{data}}"    data = data.replace("b&#39;", "") //to get rid of start curly brace code     data = data.replace("&#39;", "")  //to get rid of end curly bracecode     document.getElementById("img").src = "data:image/png;base64,"+data; // set src</script>