[Django]-Invalid block tag : 'endblock'. Did you forget to register or load this tag?

36πŸ‘

βœ…

Django didn’t recognise your starting block tag, because you have a space between the { and the %.

You also have the same error in both start and end tags in the other template file.

13πŸ‘

You simply have typos.

You should have {% not { %, and you got those typos in both of templates.

So you need to have

<!DOCTYPE html>
<html lang="en">

  <head>
    <meta charset="UTF-8">
    <title>{% block title %}{% endblock %}</title>
  </head>
  <body>
    {% block content %}   {% endblock %}
  </body>
</html>

and

{% extends "layout/layout1.html"%}


{% block title %}The Video page{% endblock %}


{% block content %}
  <h1>This is a html</h1>

  <p>This is a p tag</p>

  <a href="http://www.noobmovies.com">Click me!</a>
  <img src="https://upload.wikimedia.org/wikipedia/en/7/72/Anthony_Raneri.jpg"/>

{% endblock %}

NOTE: don’t forget about identations in html files, it makes code more readable.

πŸ‘€vishes_shell

10πŸ‘

If none of the previous answers worked for you, try the following:

You are most likely using a base.html file and have the static css being loaded on the top {% load static %} and the problem for me was that I needed to also load this in my other template file.

I’m using Django 2.0.3 and this solved the issue for me.

3πŸ‘

For me it was emacs breaking the lines up when I copied the template over, so

{% endif  

was on one line and

%} 

was on the next line. These need to be together on one line, and

{{ variable_name }}

too.

πŸ‘€excyberlabber

3πŸ‘

in my case use {% load static %} after {% extends 'base.html' %} solved.

3πŸ‘

I got this error because I mixed up {% %} and {{ }}. I had:

<title>{% user.name %} ({% user.id %})</title>

When I should have had:

<title>{{ user.name }} ({{ user.id }})</title>
πŸ‘€Carcigenicate

2πŸ‘

For me it was the issue of using i18n without putting the {% load i18n %} inside the template file (I only put it in the base template)

πŸ‘€Gal Bracha

2πŸ‘

For me the problem was with {% extends %}, it was extend.

2πŸ‘

In your Html template, ensure you {% load static %} just after your {% block content %}
before using it in the template

πŸ‘€Cryce Truly

2πŸ‘

In my case,
{% csrf token %} instead of this {% csrf_token %} solved.

If you are missed _ (underscore) in code then also you will got this error.

πŸ‘€shoaib21

0πŸ‘

Similar to @gal-bracha answer, for me the problem was caused by including a template inside another (through the {% include %} tag) and both templates making use of a {% trans "some text" %} tag. In this case, the {% load i18n %} must be written in both the including and in the included templates.

0πŸ‘

Not to answer this specific question, but to share my case which gave the same error:
In my case this same error been caused because I forgot to add the url in the link reference name:

href="{% url 'allblogs' %}".  worked.

while error was received when url was missed like below:

href="{% 'allblogs' %}". Error been generated. 

0πŸ‘

if you encounter this:
Invalid block tag on line 172: β€˜endfor’. Did you forget to register or load this tag?
Check:
Any part of your code commented, check if {% endfor %} has been repeated.
If it is repeated delete one especially the commented section.
Thank you.

πŸ‘€The Elif

0πŸ‘

in my case i used replaced {% csrf token %} with {% csrf_token %} and it seemed to work.

In any template that uses a POST form, use the csrf_token tag inside the <form> element if the form is for an internal URL, e.g.:

<form method="post">{% csrf_token %}

This should not be done for POST forms that target external URLs, since that would cause the CSRF token to be leaked, leading to a vulnerability.

πŸ‘€Jason

0πŸ‘

This also happens when you forget putting your phrase between quotes.

{% trans My phrase %}

instead of

{% trans "My phrase" %}
πŸ‘€Luke

0πŸ‘

Apparently even double space between {% endblock and content %} is also a problem in version 4.1.7
Corrected to a single space and it worked fine.i.e:

{% endblock  content %} # failed. Note the double space
{% endblock content %} # worked fine

Leave a comment