在 Pythonanywhere 上使用 render_template 的 TemplateNotFound 错误 Flask

TemplateNotFound error Flask using render_template on Pythonanywhere

自过去两个小时以来,我一直在寻找解决此问题的方法,并且在这里看到了类似的问题,但这些解决方案似乎不起作用。我是 Flask 和 Pythonanywhere 的初学者,所以我觉得解决方案可能真的很愚蠢,我可能会错过。

模板名为 givp.html,一切都是这样组织的: 主页 > 用户 > 我的网站 > 模板 >givp.html 和 主页>用户>我的网站>apllic.py

我一直使用的代码是:

app=Flask(__name__,template_folder='/home/user/mysite/templates')

 return render_template('/home/user/mysite/templates/givp.html',lst=d)

在我的本地系统上一切正常,但我一直收到错误消息。错误日志的最后一行是:

File "/home/user/.local/lib/python2.7/site-packages/flask/templating.py", line 64, in get_source raise TemplateNotFound(template) TemplateNotFound: /home/user/mysite/templates/givp.html

您在

中创建应用程序实例时已经定义了 template_folder
app=Flask(__name__,template_folder='/home/user/mysite/templates')

因此您在调用 render_template.

时只需提供模板名称(而非完整路径)

您的代码已修复:

app=Flask(__name__,template_folder='/home/user/mysite/templates')

return render_template('givp.html',lst=d)