2024-04-25 18:55:04 发布
网友
在Flask中,如何在返回特定路径的响应后运行函数?例如:
# This function takes a long time to run def long_func(): ... @app.route('/') def index(): ... return response
如果我只想在返回索引路由的响应之后运行long_func,我该怎么做呢?在
一种方法是在调用索引后重定向到调用long函数的路由:
你可以这样做:
@app.route('/') def index(): ... return redirect(url_for('run_long_function')) @app.route('/runLongFunc') def run_long_function(): long_func() return 'done'
一种方法是在调用索引后重定向到调用long函数的路由:
你可以这样做:
相关问题 更多 >
编程相关推荐