在某些情况下,我想呈现模板,而在其他情况下,我想提供模板文件。我将相同的路径传递给render_template
和send_file
,但仅send_file
起作用。
resp = render_template('templates/index.html')
resp = send_file('templates/index.html')
模板路径相对于模板根。send_file
路径是相对于应用程序根目录的。
render_template('file.html')
send_file('templates/file.html')
此外,模板路径实际上并不是文件系统路径,它们只是在默认的 Flask 情况下看起来像它们。所以“模板根”的真正意思是“模板加载器的查找路径”而不是“模板文件夹”。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句