【问题标题】:Django template how to re-use a template html file twiceDjango模板如何重复使用模板html文件两次
【发布时间】:2014-05-02 09:56:12
【问题描述】:

我有三个文件:

  1. base.html
  2. results.html 扩展 base.html
  3. results_only.html(独立)

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

我如何“导入”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 的内容。

希望我的问题很清楚。

【问题讨论】:

    标签: html django django-templates


    【解决方案1】:

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

    {% include "results_only.html" %}
    

    我认为一切都很清楚:)

    【讨论】:

    • 谢谢,我不想说我尝试过搜索,但有时您无法找到正确的搜索内容。在这种情况下“包含”,我搜索了“块中的块”“嵌套块”等。人类仍然更聪明地猜测我想要什么:)
    猜你喜欢
    • 2018-10-31
    • 2021-02-03
    • 1970-01-01
    • 1970-01-01
    • 2014-03-13
    • 2011-07-11
    • 1970-01-01
    • 2014-05-15
    • 2018-02-06
    相关资源
    最近更新 更多