###前提・実現したいこと
matplotlibで画像が作られていない。
最終的にはhtml(result.html)に埋め込んで表示させたいが、views.pyで画像が作られていないように思う。
###発生している問題・エラーメッセージ
特にエラーは発生していない。
###該当のソースコード
views.pyに
from pylab import figure, axes, pie, title from matplotlib.backends.backend_agg import FigureCanvasAgg import numpy as np import matplotlib.pyplot as plt def view_plot(request): left = np.array([1, 2, 3, 4, 5]) height = np.array([100, 200, 300, 400, 500]) plt.bar(left, height) filename = "output.png" plt.savefig(filename) response = HttpResponse(content_type="image/png") image.save(response, "PNG") return response def result(request): return render(request, 'result.html')
と書いた。
result.htmlに
<body> <img src='/accounts/view_plot' width=300 height=300> </body>
と書いた。
###試したこと
ブラウザのアクセス時にPythonは立ち上がっているから、おそらくview_plotメソッドの途中までは実行されていると思われる。