diff --git a/src/app.py b/src/app.py index d313ebcd59f009da566bd7efd0a44fc216e522d8..c0f6820b4b709963368b5b865cef5e82b2283689 100644 --- a/src/app.py +++ b/src/app.py @@ -3,7 +3,7 @@ from flask import Flask, request, send_from_directory from flask import render_template import psycopg2 from matplotlib import pyplot as plt -from io import BytesIO +from io import StringIO import base64 database = conn = psycopg2.connect( @@ -31,13 +31,11 @@ def publishers(): rows = cursor.fetchall() lists = list(zip(*rows)) - buffer = BytesIO() + buffer = StringIO() fig = plt.figure(figsize = (15, 15)) plt.pie(lists[0], labels = lists[1]) - fig.savefig(buffer, format="png") - data = str(base64.b64encode(buffer.getvalue()), "utf-8") - image = f"data:image/png;base64,{data}" - return render_template("publishers.html", title="Publishers", image = image) + fig.savefig(buffer, format="svg") + return render_template("publishers.html", title="Publishers", image = buffer.getvalue()) @app.route("/") diff --git a/src/templates/publishers.html b/src/templates/publishers.html index ac447e6934bdffd6b788cc79be69b49d678df35c..f147ef95cd961f16b6331580cd7f1f8bb62baeaa 100644 --- a/src/templates/publishers.html +++ b/src/templates/publishers.html @@ -3,5 +3,7 @@ {% block content %} <h1>Publishers</h1> -<img width="100%" src="{{ image }}"> +<img width="100%"> +{{ image | safe }} +</img> {% endblock content %}