Flask获取mysql,不刷新pag

2024-09-30 20:33:26 发布

您现在位置:Python中文网/ 问答频道 /正文

我刚开始接触Python和烧瓶(为了树莓派)。我想要一个web应用程序,显示数据从mysql没有刷新页面我已经尝试过了

    app = Flask(__name__)
    app.config['MYSQL_HOST'] = 'localhost'
    app.config['MYSQL_USER'] = 'root'
    app.config['MYSQL_PASSWORD'] = 'raspberry'
    app.config['MYSQL_DB'] = 'tesdb'
    mysql = MySQL(app)


    @app.route('/')
    def interactive():
        return render_template('interactive.html')
    @app.route('/ambildata')
    def ambildata():
    cur = mysql.connection.cursor()
    cur.execute('''SELECT*FROM contoh WHERE id = 1''')
    result = cur.fetchall()
    return jsonify(result = result)

在交互式.html在

^{pr2}$

但是我看不到网页上的数据


Tags: 数据configappreturn烧瓶defhtmlmysql