烧瓶模板未找到 [英] Flask Template Not found

查看:229
本文介绍了烧瓶模板未找到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从瓶子实现一个简单的静态网站,但浏览器说没有找到模板,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文件夹。

所以你有一些选择,


  1. 重命名模板模板

  2. 提供一个 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,

  1. rename template to templates
  2. supply a template_folder param to have your template folder recognised by the flask app:

    app = Flask(__name__, template_folder='template')
    

这篇关于烧瓶模板未找到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆