Converting matplotlib png to base64 for viewing in html template

前端 未结 2 1608
粉色の甜心
粉色の甜心 2020-12-01 09:35

Background

Hello, I am trying to make a simple web app, following a tutorial, that calculates a dampened vibration equation and returns a png of the result to the h

相关标签:
2条回答
  • 2020-12-01 09:57

    Try adding the section meta charset="utf-8" into the HEAD section of your template. That worked for me :-)

    0 讨论(0)
  • 2020-12-01 10:05

    The beginning of the data in the template gives a clue to what's happening. ' is the HTML entity for a single quote '. Combined with the preceding b, b', it looks like the representation of a byte string, rather than the contents of the string.

    Decode the byte string to a string before trying to render them with Jinja.

    render_template('result.html', result=figdata_png.decode('utf8'))
    

    Jinja renders the string representation of objects in {{ }}. The string representation of a byte string includes the b'' to distinguish it from a Unicode string. So you have to decode in order to display their value directly.

    0 讨论(0)
提交回复
热议问题