jinja2.exceptions.TemplateSyntaxError in flask

499 Views Asked by At

I can't get rid of this exception and I have no idea what's wrong. Thanks for everything.

This is my python file

app = Flask(__name__)
@app.route("/login")
def login():
    return render_template("login.html")

And this is my login.html


{% extends = "layout.html" %}


{% block title %}
    Login
{% endblock %}

{% block heading %}Login {% endblock %}

{% block body %}
<h1>Login</h1>
{% endblock %}

And this is layout.html

<!doctype html>
<html>
  <head>
    <title>{% block title %}{% endblock %} - My Webpage</title>

  </head>
  <body>
    <h1>{% block heading %} {% endblock %}</h1>
    {% block body %}
    {% endblock %}
  </body>
</html>
2

There are 2 best solutions below

0
Vaibhav On BEST ANSWER

As per Jinja documentation, you cannot put equal to (=) for statements like {% extends %} in your template.

Your login.html should be like this:

{% extends "layout.html" %}
{% block title %}
    Login
{% endblock %}
{% block heading %}Login {% endblock %}
{% block body %}
<h1>Login</h1>
{% endblock %}

for more info Check this.

0
AzyCrw4282 On

Try {% extends "layout.html" %} instead of {% extends = "layout.html" %}.

If it doesn't work, you can also try taking out all {% %} tags and adding them back in one by one.