title: django bytesIO to base64 String & return as JSON
body: <p>I am using python 3 &amp; I have this code, trying to get base64 out of stream and returnn as json  - but not working.</p>
  
  <pre><code>       stream = BytesIO()
         img.save(stream,format='png')
         return base64.b64encode(stream.getvalue())
  </code></pre>
  
  <p>in my view, I have:</p>
  
  <pre><code>hm =mymap()
      strHM = hm.generate(data)
  return HttpResponse(json.dumps({"img": strHM}),content_type="application/json"  )
  </code></pre>
  
  <p>getting error  is not JSON serializable.  base64.b64encode(stream.getvalue()) seems giving bytes</p>