目前设计了一个网页,用户可以通过excel上传数据到数据库,下一步我想在网页上增加一个按钮,点击这个按钮,用户可以把他所上传的数据与我的数据通过图片进行对比(python代码已经写好,就是不知道怎么应用到flask框架中在网页展示出来)。或者还有没有其他的解决办法,如果解决必定采纳!感谢!!(下面是我写的代码,其实就是机械地和路由结合起来,想的是作图保存好以后,一点击按钮,展示图片)
from flask import Flask, render_template, request
import pymysql
import xlrd
import numpy as np
import matplotlib as mp
@app.route("/seedling/sevendays/figure1")
def index6():
kwargs = {
"host": "localhost",
"port": 3306,
"user": "root",
"passwd": "10868325",
"database": "lxd",
"charset": "utf8"
}
db = pymysql.connect(**kwargs)
cur = db.cursor()
sql1 = "select R400,R401 from four_ss_seven where id=1;"
cur.execute(sql1)
a = []
for row in cur:
a.append(np.array(row))
arr1 = np.array(a).T
# print(arr1)
# print(arr1.shape)
sql2 = "SELECT R400,R401 FROM four_ss_seven ORDER BY id DESC LIMIT 1;"
cur.execute(sql2)
b = []
for row in cur:
b.append(np.array(row))
arr2 = np.array(b).T
# print(arr2)
# print(arr2.shape)
com = np.array([arr1, arr2]).T
com1 = np.reshape(com, (601, 2))
# print(com1)
# print(com1.shape)
arr3 = np.arange(400, 1001)
mp.figure(figsize=(8, 6), dpi=100)
mp.plot(arr3, com1, linestyle='-')
mp.xlabel(s='wavelength', fontsize=18)
mp.ylabel(s='reflectance', fontsize=18)
mp.title(s='spectral reflectance curve', fontsize=25)
mp.savefig('./static/img/1.png')
return render_template("sd_seven_fig1.html")