烧瓶模板未找到 [英] Flask Template Not found
问题描述
从瓶子实现一个简单的静态网站,但浏览器说没有找到模板,shell返回404
jinja2.exceptions .TemplateNotFound
$ b 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)
我有以下文件结构:
$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ -template /
| --template.html
| --run.py
http://flask.pocoo.org/docs/0.10/api/
template_folder - 包含应该使用
的模板的文件夹。默认是应用程序的根目录
路径中的templates文件夹。
所以你有一些选择,
- 重命名
模板
至模板
-
提供一个
template_folder
param让您的模板
应用程序:
app = Flask(__ name__,template_folder ='template')
Implementing a simple static site from flask, but the browser says template not found, the shell returned 404
jinja2.exceptions.TemplateNotFound
TemplateNotFound: template.html
The main python code:
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 default, Flask looks in the templates
folder in the root level of your app.
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.
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')
这篇关于烧瓶模板未找到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!