首页 > 解决方案 > Django - 扩展页面未填充

问题描述

我想用 header.html 的内容填充我的 index.html。

index.html 显示所有内容 - 除了 header.html 的内容。为什么不显示“Hello World”?

在 header.html 上,我还尝试引用“index.html”或“Immo/private/index.html”,但没有成功。

项目结构

header.html:

{% extends 'private/index.html' %}

{% block content %}
<h1>fill: Hello World</h1>
{% endblock %}

索引.html:

{% load static %}
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>Index-Page</title>
    </head>
<body>
    <div class="page-header">
        <h1><a href="/">Index-Page</a></h1>
    </div>
    <div class="content container">
        <div class="row">
            <div class="col-md-8">
                    {% block content %}
                    {% endblock %}
            </div>
        </div>
    </div>
</body>
</html>

设置.py:

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'templates/')],
        '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',
            ],
        },
    },
]

我在 Windows 上的 Visual Studio 上使用 django 2.1。

标签: pythondjango

解决方案


推荐阅读