Django模板如何重复使用模板html文件两次

时间:2014-03-24 20:12:16

标签: html django django-templates

我有三个文件:

  1. base.html
  2. results.html扩展base.html
  3. results_only.html(独立)
  4. 仅使用ajax调用

    results_only.html并仅返回<tr>字段。那些<tr>行目前在results.html中重复,我宁愿让它们不重复。

    我怎样才能&#34;导入&#34; results_only.html results.html ...类似于:

    档案results.html

    {% extends "base.html" %}
    {% block header%}...{% endblock%}
    {% block content}
    <div>Results Are:</div>
    <table>
       <tbody>
          {% import "results_only.html" %}
       </tbody>
    </table>
    {% endblock %}
    

    我不想在两个地方复制results_only.html的内容。

    希望我的问题很明确。

1 个答案:

答案 0 :(得分:4)

https://docs.djangoproject.com/en/dev/ref/templates/builtins/#include

{% include "results_only.html" %}

我认为一切都很清楚:)

相关问题