首页 > 解决方案 > 如何在后台运行任务并在烧瓶中使用它的输出?

问题描述

我在两个不同的函数中使用这两行,它们基本上呈现一个页面并显示已传递的数据。传递的数据需要时间来创建,然后页面会一直加载,因为它正在等待创建数据的过程完成。我希望它以一种可以呈现我的 html 页面的方式工作,并且可以通过在后台运行进程来创建数据,然后由 html 页面使用。数据用于创建表格或使用 html 中的烧瓶模板显示它。

return render_template("preferences2.html", columns=column_names, data=data.head().values)

return render_template('results.html', Algorithm_used=str(Algorithm_used[algorithm]),
    selected_columns=columns, time_taken=time_taken,
    confusion_matrix=confusion_matrix(y_test,pred),
    labels = labels, cr=classification_report(y_test, pred, output_dict=True),
    accuracy=accuracy_score(y_test, pred), X_test=X_test[:5],
    y_test=y_test.head().values, pred=pred[0:5])

我想到了线程,但问题是它会在没有数据的情况下呈现 html 页面,并且在进程完成后不会显示任何内容。任何帮助,将不胜感激。

标签: pythonpython-3.xflaskbackground-process

解决方案


推荐阅读