设置Flask的iframe src响应

目前,我有一个关于Flask应用程序的问题。

我正在开发一个需要生成报告的Web应用程序(一些自动生成的html文件,如junit报告)。

在report_dispay页面上,我左侧有一个导航栏,其中有多个报表标题(html链接); 在右侧,有一个iframe,当点击一个链接时,将在其中显示报告。 生成报告后,我发回URI(相对文件位置,即“reports / html / index”)。 但是当我设置iframe的src属性时,烧瓶命令行打印404,找不到“reports / html / index”。

您是否知道如何将生成的报告“注册”到应用程序?

非常感谢,Vycon

您需要为这些报告注册处理程序:

# Other imports here from werkzeug.utils import safe_join # ... snip Flask setup ... @app.route("/reports/") def report_viewer(report_name): if report_name is None: abort(404) BASE_PATH = "/your/base/path/to/reports" fp = safe_join(BASE_PATH, report_name) with open(fp, "r") as fo: file_contents = fo.read() return file_contents