Python Flask Basics Templates and Static Files Template Inheritance

Ken Tuntiansin
Ken Tuntiansin
1,523 Points

Flask template block challenge 1 of 6. I'm not quite sure what is wrong.

Add two blocks to the "layout.html" template. Add a block named title around the content of the <title> tag. Add a block named content inside the <body> tag.

I'm getting "Didn't find the right number of endblocks" as response even though there are two blocks.

flask_app.py
from flask import Flask
from flask import render_template

app = Flask(__name__)


@app.route('/')
def index():
    return render_template('index.html')
templates/index.html
<!doctype html>
<html>
<head><title>Homepage</title></head>
<body>
<h1>Smells Like Bakin'!</h1>
<p>Welcome to my bakery web site!</p>
</body>
</html>
templates/layout.html
<!doctype html>
<html>
<head><title>{% block title %}Smells Like Bakin'{% endblock title %}</title></head>
<body>
{% block content %}{% endblock content %}
</body>
</html>

2 Answers

Carlos Federico Puebla Larregle
Carlos Federico Puebla Larregle
21,067 Points

There's no need of put which block is ending:

<!doctype html>
<html>
<head><title>{% block title %}Smells Like Bakin'{% endblock %}</title></head>
<body>
{% block content %}{% endblock %}
</body>
</html>

I hope that helps a little bit

Ken Tuntiansin
Ken Tuntiansin
1,523 Points

That works but it is very strange because it works fine on my computer just so. I'm guessing the test checks for {% endblock %} only.

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title> {% block title %} THIS IS TITLE {% endblock title %} </title> </head> <body> {% block content %} {% endblock content %} <p>STUFF STUFF STUFF</p> </body> </html>

Carlos Federico Puebla Larregle
Carlos Federico Puebla Larregle
21,067 Points

If you go check out the flask doc page: http://flask.pocoo.org/docs/0.10/tutorial/templates/#tutorial-templates you will see there that they use the format:

  {% block body %}{% endblock %}

Without typing which block is ending, I think that's why they are checking it out like that.