###前提・実現したいこと
matplotlibで描画したグラフをhtmlに埋め込んで表示したい。
###該当のソースコード
今、views.pyに
def graph1(): left = np.array([1, 2, 3, 4, 5]) height = np.array([100, 200, 300, 400, 500]) plt.bar(left, height) plt.show()
と書いたが、このpltで作ったグラフをどうhtmlに埋め込めばいいのかわからない。
###試したこと
https://qiita.com/5t111111/items/3d9efdbcc630daf0e48f
を参考にしたがフレームワークがFlaskなので、そもそもこのモジュールがDjangoにもあるのかわからない。
###追記
今、views.pyに
def view_plot(request): left = np.array([1, 2, 3, 4, 5]) height = np.array([100, 200, 300, 400, 500]) plt.bar(left, height) response = HttpResponse(content_type="image/png") image.save(response, "PNG") return response def index(request): return render(request, 'index.html')
と書き、
index.htmlに(accountsはアプリの名前)
<body> <header> <h1>WEB SITE</h1> </header> <img src='/accounts/view_plot' width=300 height=300> </body>
と書いたがブラウザで見ると画像がひび割れていた。
Googleの検証で500番エラーが出ていた。画像のurlを確認する方法がなく、画像のurlを確認する方法が知りたい。画像のひび割れとは
こいういう状態である。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/10/12 02:06
2017/10/12 02:07
2017/10/12 02:20
2017/10/12 02:40 編集