我在 django 应用程序中使用 matplotlib,想直接返回渲染的图像。
到目前为止我可以走plt.savefig(...)
,然后返回图像的位置。
我想做的是:
return HttpResponse(plt.renderfig(...), mimetype="image/png")
有任何想法吗?
姜戈的HttpResponse
object 支持类似文件的 API,您可以将文件对象传递给 savefig。
response = HttpResponse(mimetype="image/png")
# create your image as usual, e.g. pylab.plot(...)
pylab.savefig(response, format="png")
return response
因此,您可以直接在HttpResponse
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)