![](/img/trans.png)
[英]Django templates - can `block.super` mean something without `extends`?
[英]extends and block not working in Django Templates
我正在学习如何使用 Django 模板,但无法使用 extends 和 block 来工作。
这是我的代码。
模板.html
<!DOCTYPE html>
<html>
<body>
{% block theTitle %}
{% endblock %}
</body>
</html>
textComponent.html
{% extends 'templates/template.html' %} {% block theTitle %}
<div>what is going on?</div>
{% endblock %}
以下是文件的组织方式:
_模板
__模板.html
__textComponent.html
按照模板 inheritance ,如何:
{% extends "template.html" %}
{% block theTitle %}
<div>what is going on?</div>
{% endblock %}
根据扩展标签文档:
Normally the template name is relative to the template loader’s root directory.
所以,您可能正在寻找您的 template.html 文件:
templates/templates/template.html
这是错误的路径。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.