我有个错误:
TemplateSyntaxError at /accounts/profile/
<ExtendsNode: extends "registration/accounts/base.html"> must be the first tag in the template
我写了base.html
:
{% load staticfiles %}
<html lang="ja">
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="{% load staticfiles 'bootflat/css/bootflat.min.css' %}">
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
</head>
<body>
<nav class="navbar navbar-default" role="navigation">
<div class="navbar-header">
<p class="navbar-text">HELLO</p>
{% if user.is_authenticated %}
<p class="navbar-text">{{ user.get_username }}</p>
{% endif %}
</div>
</nav>
<div class="container">
{% block content %}
{% endblock %}
</div>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="{% static 'bootstrap/js/bootstrap.min.js' %}"></script>
</body>
</html>
profile.html
是:
{% load staticfiles %}
{% extends "registration/accounts/base.html" %}
{% block content %}
<html lang="ja">
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="{% static 'bootflat/css/bootflat.min.css' %}">
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
</head>
<body>
<a href="{% url 'kenshinresults'%}">SEE YOUR PHOTO</a>
<div class="container">
<form action="{% url 'accounts:upload_save' %}" method="POST" enctype="multipart/form-data">
{% csrf_token %}
<p>SEND PHOTO</p>
<input type="file" name="files[]" multiple>
<input type="hidden" value="{{ p_id }}" name="p_id">
<input type="submit" value="Upload">
</form>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
</body>
</html>
{% endblock %}
我发现只有base.html
被准确显示,但是当我尝试base.html
inherit profile.html
时,发生了这个错误。以前,这两个文件是准确加载的,但是当我将href="{% static 'bootflat/css/bootflat.min.css' %}"
添加到profile.html
时,出现了这个错误。为什么会发生这样的错误?我怎样才能解决这个问题?我认为添加{%loadstaticfiles%}是正确的配置文件.html,但错了吗?你知道吗
您应该将
base.html
文件视为布局,将profile.html
视为在该布局中呈现的模板文件。你知道吗因此:
load staticfiles
块应该插入到base.html
中,并且应该插入到加载静态资产的每个文件中(参见下一个要点)src=
中引用静态资产时,就足以用static
路径助手加载它profile.html
应该扩展布局base.html
,{% block content %}
中包含的任何内容都将呈现在正文的block content标记内基本.html
配置文件.html
编辑 正如丹尼尔·罗斯曼所说
该错误说明必须首先在模板中写入
extends
标记。 您可以在documentation中阅读更多关于此的信息因此,您应该首先在
profile.html
中编写{% extends "registration/accounts/base.html" %}
之后一切都会好起来的!你知道吗
相关问题 更多 >
编程相关推荐