l get stuck in this error. l'm fresh user of Django
and l m learning it by following steps on Youtube channel. l did everything same but l got this block tag error.
here is layout1 html content:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>{ % block title %}{% endblock %}</title>
</head>
<body>
{ % block content %} {% endblock %}
</body>
</html>
index html content:
{% 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 % }
views.py content:
from django.template.response import TemplateResponse
# Create your views here.
def video(request):
return TemplateResponse (request,"video/index.html",{})
how can l handle this problem? as l did double-check to make sure everything is typed same like Youtube channel and normally ,l did not get where l did a mistake.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With