Python 烧瓶罐';指定templates文件夹时找不到模板

Python 烧瓶罐';指定templates文件夹时找不到模板,python,flask,Python,Flask,我在Flask应用程序旁边的templates文件夹中创建了一个模板。当我尝试渲染此模板时,浏览器中出现404错误。为什么我不能呈现模板 from flask import Flask, render_template app = Flask(__name__, template_folder='/templates') @app.route('/') def index(): return render_template('index.html') 您不需要为应用程序指定模板文件

我在Flask应用程序旁边的templates文件夹中创建了一个模板。当我尝试渲染此模板时,浏览器中出现404错误。为什么我不能呈现模板

from flask import Flask, render_template

app = Flask(__name__, template_folder='/templates')

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

您不需要为应用程序指定模板文件夹,它会自动设置为
“模板”
。正如默认值所示,这是一条相对路径

不过,您提供了一个绝对路径,
/templates
是“文件系统根目录下的模板文件夹”。您的计算机不太可能在根目录下有模板文件夹


删除
template\u folder
参数,或删除前导的
/

您不需要为应用程序指定模板文件夹,它会自动设置为
'templates'
。正如默认值所示,这是一条相对路径

不过,您提供了一个绝对路径,
/templates
是“文件系统根目录下的模板文件夹”。您的计算机不太可能在根目录下有模板文件夹


删除
template\u folder
参数,或删除前导的
/

删除
template\u folder='/templates'
中的斜杠。它应该看起来像
template\u folder='templates'
。谢谢大家的帮助!不,这是404错误。如果你愿意,我可以提供截图作为证据。我在template_文件夹和template_文件夹中添加了斜杠,因为我在这里找到了另一个主题,当时我已经在搜索答案。好的。为什么即使没有模板文件夹部分或编辑为
template\u folder='templates'
的部分也找不到模板?请从
template\u folder='/templates'
中删除斜杠。它应该看起来像
template\u folder='templates'
。谢谢大家的帮助!不,这是404错误。如果你愿意,我可以提供截图作为证据。我在template_文件夹和template_文件夹中添加了斜杠,因为我在这里找到了另一个主题,当时我已经在搜索答案。好的。为什么即使没有模板文件夹部分或编辑为
template\u folder='templates'
的部分,flask也找不到模板?