2👍
The first option would almost certainly be easier. Just map a URL to the view that calls the matplotlib code, and return the image data there.
For the second option, you could embed image data in HTML by using a data
uri as the source of your image in the template, but this doesn’t really seem to be necessary.
Source:stackexchange.com