【发布时间】:2017-08-05 10:58:58
【问题描述】:
我正在重建我的所有模板,使其变得更易于管理和自定义,树看起来像这样:
├───core
│ └───templates
│ └───base.html (original, touches every page)
│ ...
│
├───app1
│ └───templates
│ ├───base.html (extends from core/base.html, only touches app1)
│ └───file1.html (extends from app1/base.html)
│ ...
│
└───app2
└───templates
├───base.html (extends from core/base.html, only touches app2)
└───file2.html (extends from app2/base.html)
...
要将app1 的模板连接到core 的模板,我使用{% extends '../../core/templates/base.html' %},在核心应用程序中会有{% block container %}{% endblock %} 作为示例,在app1、app2 中会有其他{% block other_content %}{% endblock %} 块.如您所见,块也是嵌套的。
问题是我收到了这个错误:
相对路径“../../core/templates/base.html”指向模板“base.html”所在的文件层次结构之外。
问题:我想知道在不进行硬编码的情况下解决此问题的最佳方法是什么?
【问题讨论】: