【问题标题】:AppEngine: loading templates from a static directory (not just '/')AppEngine:从静态目录(不仅仅是“/”)加载模板
【发布时间】:2011-09-25 05:32:45
【问题描述】:

我正在尝试让template.render()(导入为:from google.appengine.ext.webapp import template)使用位于应用程序根目录以外的目录中的模板。

我有一个名为static 的目录,我想在其中保存我的模板。或者,我稍后会将其更改为 static/templates,但这并不重要。

问题? TemplateDoesNotExist: index.html,可悲的例外。

这个:

path = os.path.join(os.path.dirname(__file__), 'index.html')
logging.debug(path)
self.response.out.write(template.render(path, template_values))

.. 有效,但是这个:

path = os.path.join(os.path.dirname(__file__), 'static/index.html')
logging.debug(path)
self.response.out.write(template.render(path, template_values))

.. 没有。

/static 已添加到 app.yaml,尽管它应该无关紧要。

感谢您的建议。

【问题讨论】:

    标签: django google-app-engine templates


    【解决方案1】:

    /static 添加到app.yaml 确实会导致/static 中的文件被区别对待。

    请参阅http://code.google.com/appengine/docs/python/config/appconfig.html#Static_File_Handlers 并注意:

    如果你有数据文件需要应用程序代码读取,数据文件必须是应用程序文件,不能通过静态文件模式匹配。

    模板是数据文件。

    【讨论】:

      猜你喜欢
      • 2015-11-08
      • 2015-02-06
      • 2012-07-25
      • 2016-02-23
      • 2015-02-05
      • 2015-08-28
      • 2012-11-05
      • 2018-04-14
      • 2014-09-15
      相关资源
      最近更新 更多