【问题标题】:Django template inheritance not renderedDjango模板继承未呈现
【发布时间】:2018-04-11 23:21:54
【问题描述】:

我正在关注template inheritance 上的 django 文档,我认为我的代码是正确的,但它不起作用,模板 people_index.html 未呈现。

我有三个模板,base.html、base_index.html、people_index.html,每个模板都继承于前一个模板。像这样:

base.html

{% include "base/header.html" %}
<body>
{% include "base/navbar.html" %}
{% include 'base/messages.html' %}

    <div class="container container-content">
        {% block content %}
        {% endblock content %}
    </div><!-- /.container -->
</body>
</html>

base_index.html

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

<h3 class="snps-slim-font">Index de {{ index_of }}</h3>
<div class="input-group"> <span class="input-group-addon">Filtrar</span>

    <input id="filter" type="text" class="form-control" placeholder="Ingrese un criterio">
</div>
<table class="table table-hover table-condensed">
        {% block table_content %}
        {% endblock table_content %}
</table>

最后是 people_index.html

{% extends "base/base_index.html" %}
{% block table_content %}
    <thead>
        <tr>
            <th class="snps-slim-font">APELLIDOS</th>
            <th class="snps-slim-font">NOMBRES</th>
            <th class="snps-slim-font">DOCUMENTO</th>
            <th class="snps-slim-font">CUIL</th>            
            <th class="snps-slim-font">ACCIONES</th>
        </tr>
    </thead>
    <tbody class="searchable">
        {% for person in object_list %}
        <tr>
            <td>{{ person.last_names }}</td>
            <td>{{ person.first_names }}</td>
            <td>{{ person.document_number }}</td>
            <td>{{ person.cuil_number }}</td>           
            <td class="snps-text-align-center">
                <a href="{% url 'people:person-detail' person.id %}" title="ver perfil"><i class="glyphicon glyphicon-eye-open" aria-hidden="true"></i></a>&nbsp;<a href="{% url 'people:person-update' person.id %}" title="editar perfil">  <i class="glyphicon glyphicon-edit" aria-hidden="true"></i></a></td>
        </tr>
        {% endfor %}
    </tbody>
{% endblock table_content %}

有人问时的看法:

class PersonListView(LoginRequiredMixin, PermissionRequiredMixin, ListView):
    model = Person
    template_name = 'people/people_index.html'
    permission_required = ('people.can_view_list')
    def get_context_data(self, **kwargs):
        context = super(PersonListView, self).get_context_data(**kwargs)
        return context

谢谢。

【问题讨论】:

    标签: django django-templates


    【解决方案1】:

    base.html你用过

    {% block content %}{% endblock %}
    

    但是在base_index.html 你没有添加它们。尝试将此块添加到base_index.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-10-27
      • 2015-04-01
      • 1970-01-01
      • 2013-01-09
      • 2020-06-15
      • 2014-05-04
      相关资源
      最近更新 更多