Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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,073 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>

Why is that when entering the title, you do not use ' in beginning of title, and if you do Workspace does not accept the code?

Carlos Federico Puebla Larregle
Carlos Federico Puebla Larregle
21,073 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.