0

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

1 Answers1

0

Found a solution that works for my needs.. I set the image source in the template to the view in my original question then used this solution (How to create a JavaScript callback for knowing when an image is loaded?) to detect when the image was done loading and prevent the template from displaying until the image request finished