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?
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?
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
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..
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!!!!
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!
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:
{% 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" %}
Remove all comments at the top of the file and place {% extends 'base.html' %}
at the 1st line.
© 2022 - 2024 — McMap. All rights reserved.