gpt4 book ai didi

python - TemplateSyntaxError 位于/accounts/profile/

转载 作者:太空宇宙 更新时间:2023-11-03 21:11:31 25 4
gpt4 key购买 nike

我得到一个错误:

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 继承 profile.html 时,出现了这个错误。之前,这两个文件加载准确,但是当我添加 href="{% static 'bootflat/css/bootflat.min.css' %}"profile.html,出现此错误。为什么会出现这样的错误?我怎样才能解决这个问题?我认为在 profile.html 中添加 {% load staticfiles %} 是正确的,但这是错误的吗?

最佳答案

您应该将您的 base.html 文件视为一个布局,并将您的 profile.html 视为在此布局内呈现的模板文件。

出于这个原因:

  • load staticfiles block 应该插入到 base.html 中,并且应该插入到您加载静态 Assets 的每个文件中(见下一个要点)
  • 当您在 src= 中引用静态 Assets 时,足以使用 static 路径助手加载它
  • profile.html 应该扩展布局 base.html 并且 {% block content %} 中包含的任何内容都将在内部呈现正文中的 block 内容标签

base.html

<html lang="ja">
<head>
<meta charset="utf-8">
{% load staticfiles %}
<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>
{% block content %}
<!-- your body is fine -->
{% end block %}
</body>
</html>

profile.html

{% extends "registration/accounts/base.html" %}

{% block content %}
<a href="{% url 'kenshinresults'%}">SEE YOUR PHOTO</a>
<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>
{% endblock %}

编辑正如丹尼尔罗斯曼所说

关于python - TemplateSyntaxError 位于/accounts/profile/,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46442566/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com