[Answered ]-How to stop the Django server from keep loading?

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

Leave a comment