子模板也可以在Django中使用子模板吗?

问题描述 投票:0回答:1

我的子模板路径是project / sales / templates / sales / table.html。

它扩展了另一个子模板sale_summary_change_list.html。

{% extends 'sales/sale_summary_change_list.html' %}

{% block result_list %}
<div class="results">
    <table>

    <thead>
      <tr>
          {% for header in table %}
        <th>
          <div class="text">
            <a href="#">{{ header }}</a>
          </div>
        </th>
          {% endfor %}
      </tr>
    </thead>

    <tbody>
      {% for row in summary %}
      <tr class="{% cycle 'row1' 'row2'}">
        <td> {{ row.color_pref }} </td>
        <td> {{ row.total | intcomma }} </td>
      </tr>
      {% endfor %}
    </tbody>

  </table>
</div>
{% endblock %}

父模板也位于同一文件夹中。 (项目/销售/模板/销售/ sale_summary_change_list.html)

{% extends 'admin/change_list.html' %}
{% load humanize %}

{% block content_title %}
<h1> Sales Summary </h1>
{% endblock %}

{% block result_list %}
    {% block table %} {% endblock %}
{% endblock %}

{% block pagination %}{% endblock %}

但是我的孩子模板没有出现。我在做什么错?

python django django-templates
1个回答
1
投票

您做错事了。只需将此代码块的{% extends 'sale_summary_change_list.html' %}替换为此{% extends 'sales/sale_summary_change_list.html' %}。它可能对您有用。

© www.soinside.com 2019 - 2024. All rights reserved.