必须是模板中的第一个标签。” Django 模板中的错误

发布于 2024-09-13 22:17:30 字数 197 浏览 2 评论 0原文

我正在使用:

{% extends "base.html" %}

我收到以下错误:

必须是模板中的第一个标签。

你能帮我吗?

I'm using:

{% extends "base.html" %}

I get the following error:

<ExtendsNode: extends "base.html"> must be the first tag in the template.

Can you please help me?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

是你 2024-09-20 22:17:31

它必须是模板中的第一个 django 模板标签。

文档说:

如果您在
模板,必须是第一个
该模板中的模板标签。
模板继承不起作用,
否则。

文档可以在此处找到

It must be the very first django template tag in your template.

Documentation says:

If you use {% extends %} in a
template, it must be the first
template tag in that template.
Template inheritance won't work,
otherwise.

Documentation can be found here

咽泪装欢 2024-09-20 22:17:31

{% extends "base.html" %} 放在编辑器的第 1 行中。从字面上把它放在第 1 行。删除顶部的所有注释(如果有的话)。

place {% extends "base.html" %} in line 1 of your editor. Literally put it in line 1. REMOVE all comments at the top if you have any..

秋心╮凉 2024-09-20 22:17:31

我也陷入了这个问题。
我使用评论作为第一个标签,它不起作用。删除它后,它起作用了。
用过这个:
{% comment %} 继承基本 html {% endcomment %}

描述我在做什么。出现错误。
删除了这个并使用扩展作为第一个模板标签。工作!!!

I also got into that problem.
I was using comment as the first tag it wasn't working.After I removed that it worked.
Used this:
{% comment %} inheriting the base html {% endcomment %}

To describe what I was doing.Got error.
Removed this and used extend as the first template tag.Worked!!!!

在风中等你 2024-09-20 22:17:31

始终记住提及 {% extends '' %} 在第一行本身,甚至不要尝试在第一行添加注释。
这肯定会解决错误!

Always remember to mention the {% extends '<TEMPLATE_NAME>' %} in the first line itself, don't even try to put comments on the first line.
This will surely resolve the error!

林空鹿饮溪 2024-09-20 22:17:31

我得到了同样的错误如下:

必须是模板中的第一个标签。

因为我使用了 {% extends %} {% comment %} 之后,如下所示:

# "templates/index.html"

{% comment %} <h1>Hello World</h1> {% endcomment %}
{% extends "base.html" %}

所以,我在{% comment %}之前使用了{% extends %},如下所示,然后解决了同样的错误:

# "templates/index.html"

{% extends "base.html" %}
{% comment %} <h1>Hello World</h1> {% endcomment %}

{% extends %} code> 在模板继承中进行了解释,如图所示如下:

  • 如果您在模板中使用 {% extends %},则它必须是该模板中的第一个模板标记。否则,模板继承将不起作用。

此外,您可以在 {# #} 这是单行注释和 html 标签,没有任何错误,如下所示。 *{# #} 不是标签,而是 Django 模板中的注释语法:

# "templates/index.html"

{# This is a single line comment #}
<h1>Hello World</h1>
{% extends "base.html" %}

I got the same error below:

<ExtendsNode: extends "base.html"> must be the first tag in the template.

Because I used {% extends %} after {% comment %} as shown below:

# "templates/index.html"

{% comment %} <h1>Hello World</h1> {% endcomment %}
{% extends "base.html" %}

So, I used {% extends %} before {% comment %} as shown below, then the same error was solved:

# "templates/index.html"

{% extends "base.html" %}
{% comment %} <h1>Hello World</h1> {% endcomment %}

{% extends %} is explained in Template inheritance as shown below:

  • If you use {% extends %} in a template, it must be the first template tag in that template. Template inheritance won’t work, otherwise.

In addition, you can use {% extends %} after {# #} which is a single line comment and html tags without any error as shown below. *{# #} is not a tag but is a comment syntax in Django Templates:

# "templates/index.html"

{# This is a single line comment #}
<h1>Hello World</h1>
{% extends "base.html" %}
向日葵 2024-09-20 22:17:31

删除文件顶部的所有注释,并将 {% extends 'base.html' %} 放在第一行。

Remove all comments at the top of the file and place {% extends 'base.html' %} at the 1st line.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文