簡體   English   中英

擴展和阻止在 Django 模板中不起作用

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM