Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/283.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 烧瓶错误:jinja2.exceptions.TemplateNotFound:_Python_Templates_Flask_Blueprint - Fatal编程技术网

Python 烧瓶错误:jinja2.exceptions.TemplateNotFound:

Python 烧瓶错误:jinja2.exceptions.TemplateNotFound:,python,templates,flask,blueprint,Python,Templates,Flask,Blueprint,我有一个Flask项目,FlaskUserAuthentication,它有一个同名的包(FlaskUserAuthentication),在该包下还有两个包,即API和Site。结构如下:- API和Site包下的\uuuu init\uuuuuuuuuuuuuuupy文件都是空的 以下是mainFlaskUserAuthenticationpackage下的\uuu init\uuuu.py文件中的代码 from flask import Flask from API.routes imp

我有一个Flask项目,
FlaskUserAuthentication
,它有一个同名的包(FlaskUserAuthentication),在该包下还有两个包,即
API
Site
。结构如下:-

API
Site
包下的
\uuuu init\uuuuuuuuuuuuuuupy
文件都是空的

以下是main
FlaskUserAuthentication
package下的
\uuu init\uuuu.py
文件中的代码

from flask import Flask
from API.routes import api
from Site.routes import site

app = Flask(__name__)

app.register_blueprint(api)
app.register_blueprint(site)
并且
run.py
具有以下特性-

from FlaskUserAuthentication import app

if __name__ == '__main__':
    app.run(debug=True)
但是,当我输入
http://127.0.0.1:5000/index
运行服务器后,出现以下错误-

jinja2.exceptions.TemplateNotFound: index.html
显然,我在
Site=>templates=>Site
文件夹下有
index.html
文件。下面是我的
Site=>routes.py
code-

from flask import Blueprint, render_template

site = Blueprint('Site', __name__, template_folder='templates') # updated


@site.route('/index')
def index():
    return render_template('index.html')


@site.route('/login')
def login():
    return render_template('login.html')
谁能帮忙吗


注:在提出一些建议后,我相应地更新了我的解决方案和问题。仍然是相同的问题。

看起来您需要通过设置
template\u文件夹来公开模板

site = Blueprint('site', __name__, template_folder='templates')

有关更多信息,请参阅。特别是,您可能需要考虑在“代码>站点/模板/站点/索引/ HTML /代码>中创建模板,并使用<代码> ReNeDelEdType(“站点/索引.html”)< /C>这样,模板就不会被应用程序模板目录中的另一个
index.html
意外覆盖。

如果文件夹结构是
Site=>templates=>Site
,则

@site.route('/index')
def index():
    return render_template('Site/index.html') #add Site folder name before index.html

小心文件夹命名-在
站点
站点
之间存在不匹配。在不区分大小写的文件系统上是可以的,但如果每次尝试在区分大小写的文件系统(例如Linux)上运行代码,都会遇到问题。要调试问题,请设置,即
app.config['EXPLAIN\u TEMPLATE\u LOADING']=True
。我遵循了你的建议,但运气不佳。我在templates文件夹下添加了另一个名为“Site”的文件夹,并更新了Blueprint实例创建。我用当前屏幕截图更新了我的问题。您更改了布局,但没有同时切换到
render\u template('Site/index.html')
。谢谢您,但前一位作者在前面提到过。您不应使用已建议的解决方案进行回答。