【问题标题】:Cannot extend base.html from parent directory无法从父目录扩展 base.html
【发布时间】:2011-09-17 11:15:20
【问题描述】:

我有这个目录结构:

root:
+pages
 -base.html
 ...
 +en
  -index.html
  ...
index.py
...

当我从 index.py 渲染 index.html 时,它说找不到 base.html

这是我在 index.html 中用来扩展 base.html 的标签:

{% extends "../base.html" %}

这是 index.py 中的代码:

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

哪个是正确的方法?我正在使用 google webapp 和 djagno 模板。

【问题讨论】:

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


    【解决方案1】:

    您不能在扩展标签中使用类似的路径。但您不需要 - 假设您的 TEMPLATE_DIRS 设置为 root/pages,您只需执行 extends "base.html"

    【讨论】:

    【解决方案2】:

    我在这里回答了一个非常类似的问题:TemplateDoesNotExist on python app-engine django 1.2 while template rendering relative paths

    那里展示的技术将允许您完全控制存储模板的目录结构。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-09-27
      • 1970-01-01
      • 2013-09-20
      • 1970-01-01
      • 1970-01-01
      • 2014-10-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多