1๐
โ
You cannot use the interactive version of matplotlib โ this will screw up โ for sure on a production environment. Just do the following:
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
from matplotlib.figure import Figure
def graphic(request):
#other stuff goes here
fig=Figure()
fig1=fig.add_subplot(1,1,1)
fig1.plot(x,y)
canvas=FigureCanvas(fig)
response=HttpResponse(content_type='image/png')
canvas.print_png(response)
return response
This is just the chart part. To implement this chart in a template just put a line like the following into your tempolate.
<img src='{% url "graphic" %}'>
And make sure that it can be found in the urls.
๐คger.s.brett
1๐
Have you tried closing the Connection and curser? i.e
c.close()
con.close()
As seen in this post:
Python MySQLdb: connection.close() VS. cursor.close()
๐คPaul Machin
- [Answered ]-Celery .env variables not used in settings.py
- [Answered ]-Use django for one page on a website?
- [Answered ]-Docker: How to rely on a local db rather than a db docker container?
Source:stackexchange.com