I am trying to display a pyplot chart to a webpage along with a template including other variables. Right now the pyplot image is being saved with PIL to the response object, however, I want more than just the image to be in the response. Is there a way to append the HTTPResponse object as a variable on a template?
I've tried using Jquery to request the plot after loading the rest of the template but the plot takes a while to render and ends up being displayed a long time after the rest of the template. I want the image to be loaded with the rest of the template
buf = io.BytesIO()
plt.savefig(buf, format='png')
buf.seek(0)
im = Image.open(buf)
response = HttpResponse(content_type="image/png")
im.save(response, "PNG")
buf.close()
plt.close(fig)
return response