django - Django:“扩展”在模板中不起作用
问题描述
我遵循了最新的 Django 文档,使用了{% extends %}
与他们在示例中相同的方式使用关键字,但我无法让它工作。我究竟做错了什么?
base.html:下面定义的content
块transaction_detail.html
工作:
<div class="row">
<div class="col-md-8">
{% if messages %}
{% endif %}
{% block content %}{% endblock %} <!--This block defined in transaction_detail.html is displaying correctly -->
</div>
...
transaction_detail.html:注意test
区块包含在content
区块内。这是允许的吗?
{% extends 'blog/base.html' %}
{% block content %} <!-- This block displays correctly -->
<div class="content-section">
<!-- Chat -->
{% block test %} <!-- This block does not display at all -->
{% endblock %}
<div>
...
房间.html:
{% extends 'blog/transaction_detail.html' %}
{% block test %}
<div class="messages">
<ul id="chat-log">
</ul>
<div class="message-input">
<div class="wrap">
<input id="chat-message-input" type="text" placeholder="Write your message..." />
<button id="chat-message-submit" class="submit">
<i class="fa fa-paper-plane" aria-hidden="true"></i>
</button>
</div>
</div>
</div>
{% endblock %}
settings.py(仅限 TEMPLATES 变量):我列出了所有应用程序INSTALLED_APPS
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
#DIRS: a list of directories where the engine should look for template source files, in search order.
'DIRS': [os.path.join(BASE_DIR, ''), # root directory
'django_project/blog/templates'], # templates in blog app
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
谁能看到我哪里出错了?我想我在 transaction_detail.html/room.html 父/子关系中遵循与 base.html/transaction_detail.html 相同的父/子关系。
解决方案
推荐阅读
- python-3.x - 来自 R&S rto 示波器的流式数据 - UnicodeDecodeError python3.6
- elasticsearch - 在嵌套的热门点击聚合中包含父 _source 字段
- react-admin - React Admin - 过滤器组件中的按钮显示两次?
- bash - bash脚本aws cloudfront创建无效路径不正确
- angular - ng-katex 没有正确安装
- python - 如何删除变量中的 {''}?
- ios - 在 ios 物理设备上运行排毒测试?
- c# - 同一站点 cookie 出现问题并从外部网站重定向
- java - 如何使用 ESAPI TPM 实现 TSS for java
- git - 存储库中的嵌套 .git 文件夹