【发布时间】:2021-05-03 15:07:23
【问题描述】:
我有一个 Flask 应用程序,它接收用户输入,然后将该输入传递给程序中的其他函数。我的问题是除非我关闭 Flask 并关闭服务器,否则其他功能将无法运行。我将如何保持服务器正常运行并调用函数?基本上,一旦用户点击“提交”,我希望所有功能都运行。
启动烧瓶应用
app.run(host = '127.0.0.1', threaded = True)
将变量传递到 HTML 表单输入
@app.route('/server_app', methods=["POST"])
def server_app():
global set_freq, set_center_freq
set_freq = request.values.get("set_freq") # <--- do whatever you want with that value
set_center_freq = request.form.get("set_center_freq")
return render_template("main_page.html")
然后调用测试函数,它现在所做的只是打印变量之一,但它不会运行,直到我使用控制 c 并关闭服务器。
def test_fun(set_freq):
print(set_freq)
#main
app.run(host = '127.0.0.1', threaded=True)
test_fun(set_freq)
只有在我手动停止烧瓶服务器运行时,它才会运行“test_fun”。
【问题讨论】: