Using matplotlib with Django Generic views

不打扰是莪最后的温柔 提交于 2019-12-03 20:18:24

There are two ways to do this depending on what you want to do.

  1. If you just want an image to be shown without any HTML, then just use a normal function view rand return a HttpResponse or if you really, really really want to use class based views override the get method and return a HttpResponse.

  2. If you want to show an HTML page with the image embedded somewhere in it. Then you can do two things

    1. Create a separate view that will respond with just the image as you did in your example, and in your HTML page just add <img src="path to that view url" />.

    2. Or if you don't want a separate view for the image then you have to create an image in the DetailView, save it to byte stream, base64 encode it and return it in your context as (for example) image. Then in your template you create an image tag with the base64 encoded data using <img src="data:image/png;base64,{{ image }}"/>.

There is a nice example here.

http://wiki.scipy.org/Cookbook/Matplotlib/Django

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!