Django 模板 {% include 不工作

Django template {% include not working

我是 Django 的新手。我在主模板中包含子模板时遇到问题。我的项目的目录结构附在快照中。我删除了默认的 views.py 并创建了我自己的名为 "views" 的文件夹,并将我的观点放入其中。这是我所做的:

1. app/views/__init__.py

from .home import *

2。 app/views/home.py

from django.shortcuts import render

def index(request):
    return render(request, 'home.html')

3。 app/templates/home.html

{% load staticfiles %}
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>
    Administrator Section
</title>

<link type="text/css" rel="stylesheet" href="{% static "css/common.css" %}"/>
<link type="text/css" rel="stylesheet" href="{% static "css/theme/transdmin.css" %}"/>
<link type="text/css" rel="stylesheet" href="{% static "css/login.css" %}"/>

<script type="text/javascript" src="{% static "js/jquery-1.10.2.js" %}"></script>
<script type="text/javascript" src="{% static "js/common.js" %}"></script>
<script type="text/javascript" src="{% static "js/login.js" %}"></script>

</head>
<body>
<div>

<div id="wrapper" class="ys-adminform">

    {% include "includes.header_logo.html" %}

    <form id="form-login" class="admin-section-form frm">

        <div class="header">
            <br/>

            <h1>Login</h1>
            <br/>
        </div>

        <div class="content">

            <div class="form-row">
                <input name="email" class="input" placeholder="Email" type="text"/>

                <div class="user-icon"></div>
            </div>
            <div class="form-row">
                <input name="password" class="input password" placeholder="Password" type="password"/>

                <div class="pass-icon"></div>
            </div>
        </div>

        <div class="footerlogin">
            <input class="button" name="btn-login" value="Authenticate" type="button"/>

            <div class="message" style="font-weight: bold; padding-top:16px;">&nbsp;</div>
        </div>

    </form>

</div>
</div>

{% include "includes.footer.html" %}
</body>
</html>

问题是 include 没有从子视图中添加内容。 我知道这可能是路径问题,但我尝试了各种选项,例如:

{% include "includes.header_logo.html" %}

{% include includes.header_logo.html %}

{% include "includes/header_logo.html" %}

{% include "templates.includes.header_logo.html" %}

{% include "app.templates.includes.header_logo.html" %}

等等

您必须使用目录斜杠 (/),而不是点 (.)

例如:

{% include "includes.footer.html" %}

变成这样:

{% include "includes/footer.html" %} 

根据 Leistungsabfall 的建议,"includes/footer.html" 有效。 header 没有工作,因为它有:

这条线路一定是崩溃了,因此 header 无法正常工作。

只需添加带有斜杠的模板文件夹....喜欢 {% 包括 "blog/footer.html" %}