Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/89.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 在Python中刷新网页时重新加载数据_Html_Mysql_Python 3.x_Flask - Fatal编程技术网

Html 在Python中刷新网页时重新加载数据

Html 在Python中刷新网页时重新加载数据,html,mysql,python-3.x,flask,Html,Mysql,Python 3.x,Flask,嗨,我知道我的英语不好,但我希望你能理解 我使用flask用python创建了一个web服务器 我从数据库导入数据,然后将其发送到html进行操作 它工作正常,但我希望每次单击“刷新”时都能看到数据更新 这是一个python代码 from flask import Flask, render_template, request, redirect,url_for import MySQLdb # modify (mysql url, mysql id , mysql password, db

嗨,我知道我的英语不好,但我希望你能理解

我使用flask用python创建了一个web服务器

我从数据库导入数据,然后将其发送到html进行操作

它工作正常,但我希望每次单击“刷新”时都能看到数据更新

这是一个python代码

from flask import Flask, render_template, request, redirect,url_for
import MySQLdb

# modify (mysql url, mysql id , mysql password, db name)

db = MySQLdb.connect("localhost","root", "4662", "nomore")
cursor = db.cursor()

# modify webpage flask

app=Flask(__name__)

@app.route('/admin',methods=['GET'])
def admin():
    if request.method=='GET':
        cursor.execute("SELECT gx FROM satcandata ORDER BY id DESC LIMIT 1")
        gx = cursor.fetchone()
        return render_template("admin.html",gx0=gx)


if __name__=='__main__':
        app.run(debug=True,host='0.0.0.0')
和html代码

<html lang="ko">
    <head>
        <meta charset="utf-8">
        <title>test homepage</title>
        <style>
        table{width:100%;}
        table,th,td{border: 1px solid #bcbcbc;}
        </style>
    </head>
    <body>
        <table>
            <caption>satcan data</caption>
        <thead>
            <tr>
                <th>num</th>
                <th>gx</th>

            </tr>
        </thead>
        <tbody>

                <th>num0:</th>
                <td>{{gx0}}</td>

            </tr>
        </tbody>
        <tfoot>
            <tr></tr>
        </tfoot>
    </table>
    </body>
</html>

测试主页
表{宽度:100%;}
表,th,td{border:1px solid#bcbc;}
卫星数据
号码
gx
num0:
{{gx0}}
如果我必须改变方法,我应该把它改成什么


或者,如果您有其他方法,请教我。

您每次都显示最后一个数据,数据库是否正在更新?使用此查询,一次最多只能有
1
行。我创建了python代码以将数据上载到MySQLdb。这将使用自动索引自动添加到数据库中,并与上述代码同时执行。我要做的是每次刷新网页上的数据。您每次都显示最后一个数据,数据库是否正在更新?使用此查询,一次最多只能有
1
行。我创建了python代码以将数据上载到MySQLdb。这是使用自动索引自动添加到数据库中的,并与上述代码同时执行。我想做的是每次刷新网页上的数据。