试图摆脱python flask应用程序中的警告

时间:2019-07-07 14:11:32

标签: python html python-3.x flask

所以我正在制作这个应用程序,并且只是测试了一些我在Google上找到的代码,以了解基本知识,但是我一直收到此警告:

  

CoreAnimation:警告,已删除线程且未提交CATransaction;在环境中设置CA_DEBUG_TRANSACTIONS = 1以记录回溯。

HTML->

<body>
    <label id="value_lable">
        {% for graph in graphs %}
        <img src="{{ graph }}">
        <br>
        {% endfor %}
    </label>
</body>

FLASK APP->

app = Flask(__name__)

@app.route('/graphs')
def graphs():
    # These coordinates could be stored in DB
    x1 = [0, 1, 2, 3, 4]
    y1 = [10, 30, 40, 5, 50]
    x2 = [0, 1, 2, 3, 4]
    y2 = [50, 30, 20, 10, 50]

    graph1_url = build_graph(x1, y1)
    graph2_url = build_graph(x2, y2)

    graph_list = [graph1_url, graph2_url]
    return render_template('graphs.html', graphs=graph_list)


if __name__ == '__main__':
    app.run(debug=True)

将MATPLOTLIB图形转换为IMG->

def build_graph(x_coordinates, y_coordinates):
    img = io.BytesIO()
    plt.plot(x_coordinates, y_coordinates)
    plt.savefig(img, format='png')
    img.seek(0)
    graph_url = base64.b64encode(img.getvalue()).decode()
    plt.close()
    return 'data:image/png;base64,{}'.format(graph_url)

0 个答案:

没有答案