5👍
✅
base64.b64encode(buffered.getvalue()) returns a byte class object. It needs to be converted to a string before passing it to a template. It can be done as follows:
img_str = base64.b64encode(buffered.getvalue()).decode('ascii')
Source:stackexchange.com