title: Matplotlib and django templates
body: <p>I have a Django application, with charts from Googles image chart api. I want to replace the charts (they are depreciated), and start using Matplotlib. </p>
  
  <p>So I have followed the example here, to get Django / Matplot to return a png:</p>
  
  <p><a href="http://wiki.scipy.org/Cookbook/Matplotlib/Django" rel="nofollow">http://wiki.scipy.org/Cookbook/Matplotlib/Django</a>.</p>
  
  <p>Now, if I want to return an HTML page, with Matplotlib images embedded, how do I go about that? I can see two options. </p>
  
  <p>1: Should I set up the HTML as one view, with another view for the chart, treating these two parts separately (I guess data would be encoded in the image URL). The HTML will be rendered, and as the image tag is rendered , it makes the second call to Django, and the chart is generated. This seems easy enough to set up, but also seems like the chart data will be passed back and forward unnecessary.  </p>
  
  <p>2: Or can I generate the Matplot lib images at the same time as the HTML, have the png's ready and send them at the same time? I guess I would have to write the file to where static files are served from. And what would be considered best practice for a naming scheme for files / cleaning up afterwards?</p>
  
  <p>Is there one method that is considered best practice over the other for this sort of thing? I assume it isn't so uncommon. </p>