render_template("x.html") 到底从哪里找?多个目录里有同名文件怎么办?能不能写成路径穿越?想加一个额外的模板目录怎么办?这篇建一个应用加两个蓝图,把每一步查找都打印出来。
render_template('a.html' ) → 应用 a
render_template('only_app.html' ) → 只在应用里
render_template('only_bp1.html' ) → 只在 bp1
render_template('only_bp2.html' ) → 只在 bp2
render_template('dir/x.html' ) → 应用的 dir/x
render_template('nope.html' ) → TemplateNotFound: 'nope.html'上一篇:Jinja2 Template Loader;下一篇:模板继承与 Block。蓝图自己的模板目录见Blueprint 的静态文件和模板目录。
[nope1, only_bp2, a] → 只在 bp2 | [a, only_bp2] → 应用 a 全都不存在 → TemplatesNotFound: none of the templates given were found: x1.html, x2.html
render_template('../secret.txt' ) → TemplateNotFound: '../secret.txt'
render_template('../other/x.html' ) → TemplateNotFound: '../other/x.html'
render_template('/etc/passwd' ) → TemplateNotFound: '/etc/passwd'
render_template('dir/../a.html' ) → TemplateNotFound: 'dir/../a.html'
render_template('dir//x.html' ) → 应用的 dir/x
render_template('./a.html' ) → 应用 a
render_template('.hidden.html' ) → hidden
render_template('dir\\x.html' ) → TemplateNotFound: 'dir\\x.html'
render_template('a.html\x00' ) → TemplateNotFound: 'a.html\x00' render_template('extra_only.html') → 额外目录里的
render_template('a.html') → 应用 a render_template_string("{{ 1 + 1 }}") → 2
字符串模板里 include 文件模板: [只在应用里] ['.hidden.html', 'a.html', 'dir/x.html', 'extra_only.html', 'only_app.html', 'only_bp1.html', 'only_bp2.html']
被多处提供的模板名: {'a.html': ['bp1', '应用'], 'dir/x.html': ['bp1', '应用']}