从flask实现一个简单的静态站点,但是浏览器说找不到模板,shell返回404
jinja2.exceptions.TemplateNotFound
TemplateNotFound: template.html
主要python代码:
from flask import Flask, render_template
app = Flask(__name__)
@app.route("/")
def template_test():
return render_template('template.html', my_string="Wheeeee!", my_list=[0,1,2,3,4,5])
if __name__ == '__main__':
app.run(debug=True)
我的文件结构如下:
flask_new_practice
|--template/
|--template.html
|--run.py
最佳答案
默认情况下,Flask 会在您应用的根目录中的 templates
文件夹中查找。
http://flask.pocoo.org/docs/0.10/api/
template_folder – the folder that contains the templates that should be used by the application. Defaults to 'templates' folder in the root path of the application.
所以你有一些选择,
- 将
template
重命名为templates
提供一个
template_folder
参数,让 flask 应用程序识别您的template
文件夹:app = Flask(__name__, template_folder='template')
关于python - 找不到 flask 模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33396064/