[Answered ]-How to output a graph from Matplotlib in Django templates?

2👍

When I had a similar situation, I used two views. One used matplotilb to generate a PNG, while the other used used django templates to create an HTML page that presented the PNG (and some other data). The param sent to the template was just the PNG filename. The other view is then attached to he appropriate .png URLs.

One problem is if you want to calculate some parameters which are used both for generating the HTML and PNG. I encoded such information in the filename. This is painful, and slightly hacky, but it’s s also good for the user if all the info is in the filename when she saves it.

Leave a comment