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.
- [Django]-How do I get the object if it exists, or None if it does not exist in Django?
- [Django]-Is it possible to use FastAPI with Django?
- [Django]-ImportError: No module named django.core.wsgi Apache + VirtualEnv + AWS + WSGI
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.
- [Django]-Using Django Rest Framework, how can I upload a file AND send a JSON payload?
- [Django]-Django applying a style class based on a conditional
- [Django]-Django Queryset with year(date) = '2010'
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.
- [Django]-Why django urls end with a slash?
- [Django]-Django nested transactions β βwith transaction.atomic()β
- [Django]-Dynamically limiting queryset of related field
- [Django]-Django Rest Framework writable nested serializers
- [Django]-Django queries β id vs pk
- [Django]-Using only the DB part of Django
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>
- [Django]-How do I test Django QuerySets are equal?
- [Django]-Change a field in a Django REST Framework ModelSerializer based on the request type?
- [Django]-Coercing to Unicode: need string or buffer, NoneType found when rendering in django admin
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)
- [Django]-History of Django's popularity
- [Django]-How to apply multiple filters on a Django template variable?
- [Django]-Django, filter by specified month and year in date range
- [Django]-Django migration strategy for renaming a model and relationship fields
- [Django]-Meaning of leading underscore in list of tuples used to define choice fields?
- [Django]-How do I see stdout when running Django tests?
2π
In your Html template, ensure you {% load static %}
just after your {% block content %}
before using it in the template
- [Django]-Annotate a sum of two fields multiplied
- [Django]-Apache not serving django admin static files
- [Django]-Running django tests with sqlite
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.
- [Django]-Session data corrupted in django
- [Django]-Drawbacks to running Django under PyPy?
- [Django]-Best Fabric scripts for Django
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.
- [Django]-How to access data when form.is_valid() is false
- [Django]-Proper way to test Django signals
- [Django]-Homepage login form Django
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.
- [Django]-Pre-populate an inline FormSet?
- [Django]-Web application monitoring best practices
- [Django]-How to monkey patch Django?
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.
- [Django]-Tell if a Django Field is required from template
- [Django]-Performing a getattr() style lookup in a django template
- [Django]-How to alphabetically order a drop-down list in Django admin?
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.
- [Django]-Control the size TextArea widget look in django admin
- [Django]-Checking the number of elements in an array in a Django template
- [Django]-Get the file path for a static file in django code
0π
This also happens when you forget putting your phrase between quotes.
{% trans My phrase %}
instead of
{% trans "My phrase" %}
- [Django]-Django Rest Framework: Access item detail by slug instead of ID
- [Django]-Django: Access given field's choices tuple
- [Django]-What's the cleanest, simplest-to-get running datepicker in Django?
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
- [Django]-How to disable formatting for FloatField in template for Django
- [Django]-How do I run tests against a Django data migration?
- [Django]-How to override css in Django Admin?