あなたはおそらく次のようなことをしているでしょう:
from flask import Flask, render_template
from yourMySqlLibrary import connect_to_mysql
conn = connect_to_mysql()
# This is only executed when you start the script
data = conn.execute("SELECT * FROM MySemiRegularlyUpdatedTable")
app = Flask(__name__)
@app.route("/")
def view_data():
return render_template("view_data.html", data=data)
if __name__ == "__main__":
app.run()
その場合、解決策は、接続とクエリ呼び出しをコントローラーに移動して、ページにアクセスするたびにデータベースが再クエリされるようにすることです。
@app.route("/")
def view_data():
# Removed from above and placed here
# The connection is made to the database for each request
conn = connect_to_mysql()
# This is only executed on every request
data = conn.execute("SELECT * FROM MySemiRegularlyUpdatedTable")
return render_template("view_data.html", data=data)
このように、データが更新されたときにビューが更新されます。データへの変更を取得するためだけにサーバーを再起動する必要はありません。