Made image is not shown in html. I wrote in views.py
@login_required
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"
save_fig=plt.savefig(filename)
response = HttpResponse(content_type="image/png")
save_fig.save(response, "PNG")
return save_fig
in html
<body>
<img src='/accounts/view_plot' width=300 height=300>
</body>
in urls.py
urlpatterns = [
url(r'^view_plot$', views.view_plot,name='view_plot'),
]
cracked image is shown.
I do not know why this error happens. In Django app,output.png is saved. I doubt image is not made in view_plot.But i cannot know whether or not. What is wrong in my code?How should I fix this?