【问题标题】:TemplateNotFound error Flask using render_template on Pythonanywhere在 Pythonanywhere 上使用 render_template 的 TemplateNotFound 错误 Flask
【发布时间】:2016-06-10 03:29:53
【问题描述】:

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

该模板名为 givp.html,所有内容都以这种方式组织: 主页 > 用户 > mysite > 模板 >givp.html 和 home>user>mysite>apllic.py

我一直使用的代码是:

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

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

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

文件 "/home/user/.local/lib/python2.7/site-packages/flask/template.py", 第 64 行,在 get_source 中 raise TemplateNotFound(template) TemplateNotFound: /home/user/mysite/templates/givp.html

【问题讨论】:

    标签: python flask pythonanywhere


    【解决方案1】:

    您在创建应用实例时已经定义了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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-05
      • 1970-01-01
      • 2014-06-13
      • 2016-06-19
      • 2014-01-30
      • 2014-07-22
      相关资源
      最近更新 更多