找不到烧瓶模板
Flask Template Not found
从 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')
从 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')