【问题标题】:djangocms template inheritancedjangocms 模板继承
【发布时间】:2014-10-21 08:33:12
【问题描述】:

Django-cms 多重继承不起作用。

我有以下模板结构:

base.html
    {% block content %}
    {% endblock content %}

page1.html
    {% extends "base.html" %}
    {% block test %}
    {% endblock test %}

page2.html
    {% extends "page1.html" %}
    {% block content %}
          <div>foo</div>
    {% endblock content %}
    {% block test %}
          <div>foo</div>
    {% endblock test %}

问题是page2 HTML中的block test没有渲染。仅渲染来自 base.html 的块。如果我在 base.html 中包含块测试,也会在 page2 中呈现

【问题讨论】:

    标签: html django django-cms


    【解决方案1】:

    您的 base.html 是否包含 {% block test %}?

    您的基本模板必须包含您要覆盖的块。您可以在子模板中添加其他块,但它们必须包含在基本块中。

    https://docs.djangoproject.com/en/dev/topics/templates/#template-inheritance

    【讨论】:

      【解决方案2】:

      base.html 是您的顶级模板。这通常是以 html doctype 开头并以 &lt;/html&gt; 标记结尾的东西。其他一切都必须有一个地方可以进去。你所拥有的只是一个content 块。

      那么test 块会去哪里?您已尝试将其放入 page1.html,但仍需要在父模板中放置一个位置。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-04-17
        • 2013-12-13
        • 2010-10-04
        • 2011-04-08
        • 2016-01-19
        • 2016-11-14
        • 2011-02-27
        • 1970-01-01
        相关资源
        最近更新 更多