Issue
I'm starting to use Flask and I find myself standing on this next mistake:
jinja2.exceptions.TemplateSyntaxError: Encountered unknown tag 'endblock'.
I don't know exactly where the error is, I've already redo the code but I still have the same problem! Here's the code:
app.py
from flask import Flask, render_template
app = Flask(__name__)
@app.route("/")
def index():
return "Hello, World!"
@app.route("/page1")
def page1():
return render_template("page1.html")
@app.route("/page2")
def more():
return render_template("page2.html")
layout.html
<html>
<head>
<title> My website </title>
</head>
<body>
<h1> {$ block heading %}{% endblock heading %}} </h1>
{% block body %}
{% endblock body %}
</body>
</html>
page1.html
{% extends "layout.html" %}
{% block heading %}
First Page
{% endblock heading %}
{% block body %}
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
</p>
<a href="{{ url_for('more') }}"> Leia Mais. </a>
{% endblock body %}
Solution
Use this:
{% endblock %}
In place of the specific endblock things you're using.
Oh, I also see you're doing this:
{$ block heading %}{% endblock heading %}}
There are three problems here:
- you have a
$
symbol, and - you have two end
}
- as mentioned before, the endblock should just be this:
{% endblock %}
Answered By - mechanical_meat
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.