So I am trying to replicate the code done in Flask lecture video, which still revolves around submitting and inputting a user's name. I think I have done the exact same code as Brian's, but the code throws me an error message.

Here is the code for application.py:

from flask import Flask, flash, jsonify, redirect, render_template, request, session, url_for
from flask_session import Session
from werkzeug.exceptions import default_exceptions, HTTPException, InternalServerError
from werkzeug.security import check_password_hash, generate_password_hash

#Configure application
app = Flask(__name__)

def index():
    return render_template("index.html")

def hello():
    name = request.args.get("name")
    if not name :
        return render_template("failure.hmtl")
        return render_template("hello.html",name=name)

And the index.html:

{% extends "layout.html" %}

{% block body %}
        <form action="/hello">
            <input name = "name" type="text">
            <input type ="submit">

{% end block %}

The hello.html:

{% extends "layout.html" %}

{% block body %}
        Hello, {{ name }} !
{% end block %}

The failure.html:

{% extends "layout.html" %}

{% block style %}

{% endblock %}

{% block body %}
        You must provide a name!
{% end block %}

And last is the layout.html:

<!DOCTYPE html>

<html lang="en">
            {% block style %}
            {% endblock %}


        {% block body %}
        {% endblock %}

In layout.html, there are those two red circles with cross in the center beside these two lines

 {% block style %}
 {% endblock %}

They also appear in the lecture video. But when run, his code works, while mine doesn't. The error message looks like this on the IDE:jinja2.exceptions.TemplateSyntaxError: Encountered unknown tag 'end'. Jinja was looking for the following tags: 'endblock'. The innermost block that needs to be closed is 'block'. and just 500 Internal Server Error on the webpage.

Anybody care to explain why the code doesn't work? I mean it's supposed to be basic and if I can't get this right then I won't have much luck with other more advanced problems. Thanks!


The answer is in the error message:

Encountered unknown tag 'end'. Jinja was looking for the following tags: 'endblock'.

You've got multiple instances of

{% end block %}

when it should be

{% endblock %}

See the difference?

  • Yeah, thanks for pointing that out! – speedy_catch Jan 28 '20 at 9:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .