Flask 请求从模板中获取 HTML 数据?

Flask Request to get HTML data from a template?

是否可以使用 flask 请求从模板中获取 html 数据?

例如,这就是我正在尝试的。

html = request.get_data(render_template('custom_templates/basic.html'))

然后将 html 信息传递到模板中:

 return render_template('index.html', html=html)

我无法使用下面的 URL 查看 basic.html 文件(未找到 404),这就是我尝试“render_template”的原因。 http://127.0.0.1:5000/templates/custom_templates/basic.html

我设法使用 make_response 做到了这一点。

from flask import make_response

resp = make_response(render_template('custom_templates/basic.html'))
html = resp.get_data(as_text=True)

如果您不添加 as_text=True 则它 returns 以字节为单位。