Python 找不到烧瓶模板
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33396064/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Flask Template Not found
提问by saviour123
Implementing a simple static site from flask, but the browser says template not found, the shell returned 404
从flask实现一个简单的静态站点,但是浏览器说找不到模板,shell返回404
jinja2.exceptions.TemplateNotFound
TemplateNotFound: template.html
The main python code:
主要的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)
I have the following file structure:
我有以下文件结构:
flask_new_practice
|--template/
|--template.html
|--run.py
采纳答案by Jeffrey Godwyll
By default, Flask looks in the templates
folder in the root level of your app.
默认情况下,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.
http://flask.pocoo.org/docs/0.10/api/
template_folder – 包含应用程序应使用的模板的文件夹。默认为应用程序根路径中的“模板”文件夹。
So you have some options,
所以你有一些选择,
- rename
template
totemplates
supply a
template_folder
param to have yourtemplate
folder recognised by the flask app:app = Flask(__name__, template_folder='template')
- 重命名
template
为templates
提供一个
template_folder
参数,让template
Flask 应用程序识别您的文件夹:app = Flask(__name__, template_folder='template')