如何通过刷新页面来重启Flask进程 [英] How to restart Flask process by refreshing page
问题描述
我有一个简单的 Flask
应用程序,该应用程序使用一组参数查询数据库,然后绘制结果.效果很好,但是如何在进程仍在运行时重新启动进程(查询数据库,绘制数据)并刷新页面,或者再次单击提交按钮?
I have a simple Flask
application that queries a database using a set of parameters and then plots the result. This works fine, but how do I restart process(querying database, plotting data) whenever its still running and I do a refresh of the page or I click the submit button again?
app = Flask(__name__)
@app.route('/', methods=['GET', 'POST'])
def index():
form = InputForm(request.form)
if request.method == 'POST' and form.validate():
data = queryDatabase(form.startdate.data, form.enddate.data)
result = plotData(data)
else:
result = None
return render_template('view.html', form=form, result=result)
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000, debug=True)
view.html
view.html
<form method=post action="">
<table>
{% for field in form %}
<tr>
<td>{{ field.label }}</td>
<td>{{ field }}</td>
</tr>
{% endfor %}
</table>
<p><input type=submit value=Submit></form></p>
<p>
{% if result != None %}
<img src="{{ result }}" width="500">
{% endif %}
</p>
推荐答案
您应该使用队列,例如别人提到的Celery + Redis或Celery + RabbitMq.您可以在此处举例: http://eon01.com/blog/celery-worker-rabbitmq-broker-by-step-by-troduction/
You should use queues For example Celery + Redis or Celery + RabbitMq as mentioned by others. You can examples here: http://eon01.com/blog/celery-worker-rabbitmq-broker-step-by-step-introduction/
这篇关于如何通过刷新页面来重启Flask进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!