【问题标题】:Django Template Syntax Error in Google App EngineGoogle App Engine 中的 Django 模板语法错误
【发布时间】:2011-03-31 19:44:50
【问题描述】:

我尝试在 localhost 上启动我的 Google App Engine 应用程序,但遇到了一个 Django 错误,我被卡住了。

“TemplateSyntaxError: Template 'base/_base.html' 无法扩展,因为它不存在”

我将模板放在 /templates 中,然后将 _base.html 和 index.html 放在 /templates/base 中。谢谢! 埃米尔@proudn00b.com

错误:

Traceback (most recent call last):
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/ext/webapp/__init__.py", line 511, in __call__
    handler.get(*groups)
  File "/Users/emilepetrone/code/thebuswheel/main.py", line 65, in get
    outstr = template.render(temp, { 'path': path })
….

…..
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/django/django/template/loader_tags.py", line 58, in get_parent
    raise TemplateSyntaxError, "Template %r cannot be extended, because it doesn't exist" % parent
TemplateSyntaxError: Template 'base/_base.html' cannot be extended, because it doesn't exist

参考:

def get(self):

    path = self.request.path

    temp = os.path.join(
        os.path.dirname(__file__),
        'templates' + path)

    if not os.path.isfile(temp):
        temp = os.path.join(
            os.path.dirname(__file__),
            'templates/base/index.html')

    outstr = template.render(temp, { 'path': path })        
    self.response.out.write(outstr)

【问题讨论】:

    标签: python google-app-engine django-templates


    【解决方案1】:

    您可以仔细检查的另一件事是确保 TEMPLATE_DIRS 设置中的一个路径指向您的模板的根目录。

    还要确保它是设置中的完整绝对路径,而不是相对于项目。

    【讨论】:

      【解决方案2】:

      我认为您需要查看您的模板。回溯的重要部分在最后:

      模板 'base/_base.html' 无法扩展,因为它不存在

      您有名为“base/_base.html”的模板吗?如果没有,请查找其他正在尝试扩展它的模板文件。

      【讨论】:

      • 我确实有 base/_base.html 文件,这是唯一的模板文件。 Def 部分的挫折
      • 也许显示您的模板和 yaml 配置文件会有所帮助。 :-)
      • 文件对于stackoverflow来说太长了,所以我把它们贴在博客上...proudn00b.com/post/976956081/buswheel-files-4-error
      【解决方案3】:

      @jps 的解决方案

      将 base/_base.html 重命名为 base.html,没有子目录。使用新路径更新 index.html。

      【讨论】:

        猜你喜欢
        • 2011-12-19
        • 2011-08-06
        • 2019-01-03
        • 1970-01-01
        • 2010-10-20
        • 2011-09-18
        • 2017-03-12
        • 2011-04-30
        相关资源
        最近更新 更多