这个确切的用例恰好是flask的open_resource
API调用文档以及问题中链接的蓝图文档中使用的示例。
具体来说,参考文档说:
若要查看其工作原理,请考虑以下文件夹结构:
/myapplication.py
/schema.sql
/static
/style.css
/templates
/layout.html
/index.html
with app.open_resource('schema.sql') as f:
contents = f.read()
do_something_with(contents)