kylie.a..
29
Flask正在寻找templates/frontend/src/view_notifications.html您的模板文件.您需要将模板文件移动到该位置或更改默认模板文件夹.
根据Flask文档,您可以为模板指定不同的文件夹.它默认templates/位于您应用的根目录中:
import os
from flask import Flask
template_dir = os.path.abspath('../../frontend/src')
app = Flask(__name__, template_folder=template_dir)
更新:
在Windows机器上自己测试后,模板文件夹确实需要命名templates.这是我使用的代码:
import os
from flask import Flask, render_template
template_dir = os.path.dirname(os.path.dirname(os.path.abspath(os.path.dirname(__file__))))
template_dir = os.path.join(template_dir, 'frontend')
template_dir = os.path.join(template_dir, 'templates')
# hard coded absolute path for testing purposes
working = 'C:\Python34\pro\\frontend\\templates'
print(working == template_dir)
app = Flask(__name__, template_folder=template_dir)
@app.route("/")
def hello():
return render_template('index.html')
if __name__ == "__main__":
app.run(debug=True)
有了这个结构:
|-pro
|- backend
|- app.py
|- frontend
|- templates
|- index.html
更改'templates'to的任何实例'src'并重命名templates文件夹会'src'导致收到相同的错误OP.