我是Django的新手。我遇到问题,包括主模板中的子模板。我的项目的目录结构附加在快照中。我删除了默认的views.py并创建了我自己的名为“views”的文件夹,并将我的视图放入其中。这就是我所做的:
1。应用程序/视图/ __初始化__。PY
from .home import *
2。应用程序/视图/ home.py
from django.shortcuts import render
def index(request):
return render(request, 'home.html')
第3。应用程序/模板/ 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;"> </div>
</div>
</form>
</div>
</div>
{% include "includes.footer.html" %}
</body>
</html>
问题是包括不从子视图添加内容。 我知道它可能是一个路径问题,但我尝试了各种选项,如:
{% 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" %}
等
答案 0 :(得分:1)
您必须使用目录斜杠(/
),而不是点(.
)
例如:
{% include "includes.footer.html" %}
成为这个:
{% include "includes/footer.html" %}
答案 1 :(得分:0)
根据Leistungsabfall的建议,&#34;包括/ footer.html&#34;作品。标题无效,因为它有:
这一行必须崩溃,因为哪个标题不起作用。
答案 2 :(得分:0)
只需添加带有斜线的模板文件夹即可。 {%包括“ blog / footer.html”%}