无法正确扩展django模板?

时间:2017-08-13 17:32:43

标签: html django django-templates

我有一个base.html模板,其中包含基本的html定义。其他模板定义如下

// pages/dashboard.html
{% extends 'base.html' %}

{% block body %}
    {% include 'components/nav.html' %}
    {% include 'components/dashboard.html' %}
{% endblock %}

// components/dashboard.html
<div class="page-container">
    <div class="main-page">
        {% block dashboard %}
        {% endblock %}
    </div>
</div>

// mailer/new.html
{% extends 'pages/dashboard.html' %}
{% block dashboard %}
    <h1>hello</h1>
{% endblock %}

视图呈现mailer/new.html问题是包含<h1>hello</h1>的块无法正常工作。我哪里错了?

1 个答案:

答案 0 :(得分:2)

var rendered = renderer.create( <ReportAsTableView reportUUID="e451ae04-4881-11e7-a919-92ebcb67fe33" reportParameters={params} fetchData={FAKE_RESPONSE} /> ); expect(rendered.toJSON()).toMatchSnapshot(); 不起作用。请参阅documentation for that tag中的注释:

  

包含之前对进行评估。这意味着包含来自另一个块的块的模板将包含已经被评估和呈现的块 - 而不是可以被扩展模板覆盖的块。