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

Remove everything from "index.html" except for the extends and block tags and their contents.

WHERE AM GETTING IT WRONG PLEASE INDICATE ON MY CODE - The error is YOUR "index html " has more contents

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
{%extends "layout.html"%}
{%block title%}Homepage{%endblock%}
{%block content%}Smells Like Bakin'!Welcome to my bakery web site!{%endblock%}
templates/layout.html
<!doctype html>
<html>
<head><title>{%block title%}Smells Like Bakin'{%endblock%}</title></head>
<body>
{%block content%}{%endblock%}
</body>
</html>

5 Answers

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

Let's look at the original version of 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>

And let's look at your version at step 5.

{%extends "layout.html"%}
{%block title%}Homepage{%endblock%}
{%block content%}Smells Like Bakin'!Welcome to my bakery web site!{%endblock%}

The instructions are to remove everything except for the extends and block tags, and their contents. You removed the HTML tags in the content block, though.

I'll make the error message more explicit, saying that your template seems to have the wrong content in it, but this isn't a case of the checker being too picky. You weren't told to change any of the HTML inside of the blocks, so don't change the HTML inside of the blocks.

Chris Freeman
Chris Freeman
Treehouse Moderator 68,457 Points

While I agree than the error message is misleading by using the words "has extra content" instead of "wrong content". I counter that the code as is without the HTML tags passes Task 5 if extra spaces are added in the template tags surrounding "title" and "content".

If the scutiny is around the missing HTML tags then that should have been caught in the passing Task 4 solution I posted which does not have the HTML tags.

I think it is confusing for students if passing code from one task becomes incorrect in a subsequent seemingly unrelated task objective.

I was going point out to Taurayi about the missing HTML tags but their modified code passes without the HTML tags hence spawning this thread.

Chris Freeman
Chris Freeman
Treehouse Moderator 68,457 Points

I think the main point is the implied correct code with the HTML tags fails if there are no spaces next to the % in the template tags. Which brings us back to the the original aspect of the pass/fail situation regarding readability with spaces next to the % vs. syntax correctness on the template tags without the spaces.

I think Task 4 needs to check for the HTML tags and Task 5 needs to relax on the template tag spacings.

Thanks for putting up my over specificity on this. :-)

Kenneth Love
Kenneth Love
Treehouse Guest Teacher

Alright, yet another update the CC.

The content check is correct where it is. Each step should only test for the changes required in that step. Step 4 doesn't require you to delete anything so we shouldn't test that things didn't get deleted there. Anyway, it's a bit more lenient in the Jinja2 checks on Step 5 and a bit more precise in the content checks.

There might still be some gaps but I'm pretty happy with it.

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,457 Points

I would say your code is fine. And that the checker is inconsistent in checking for spaces around template tags.

If task 4 passes with:

{%extends "layout.html"%}
<!doctype html>
<html>
<head><title>{%block title%}Homepage{%endblock%}</title></head>
<body>
{%block content%}Smells Like Bakin'!Welcome to my bakery web site!{%endblock%}
</body>
</html>

Then task 5 should pass with:

{%extends "layout.html"%}
{%block title%}Homepage{%endblock%}
{%block content%}Smells Like Bakin'!Welcome to my bakery web site!{%endblock%}

But it doesn't. Testing many combinations it appears that the checker is looking for spaces around certain template tags. After adding spaces to the block title and block content template tags, this passes:

{%extends "layout.html"%}
{% block title %}Homepage{%endblock%}
{% block content %}Smells Like Bakin'!Welcome to my bakery web site!{%endblock%}

Strictly speaking the spaces are for readability and are not part of the syntax spec.

Tagging Kenneth Love to check for inconsistency in the checker.

Vittorio Somaschini
Vittorio Somaschini
33,371 Points

Hello Taurayi.

You might want to use the proper spacing inside the tags.

That is the only problem I can see here.

Vittorio

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

You're supposed to use a {{ super() }} in the title at one point in the challenge.

Chris Freeman
Chris Freeman
Treehouse Moderator 68,457 Points

Correct, but that is on Task 6 of 6. This issue is happening at Task 5.

Kenneth Love
Kenneth Love
Treehouse Guest Teacher

You're right. New comment with what's actually wrong.

I cannot get mine to pass for the life of me

{%extends "layout.html"%}
{% block title %}Homepage{%endblock%}
{% block content %}Smells Like Bakin'!Welcome to my bakery web site!{%endblock%}

[MOD: added ```html+jinja formatting -cf]

Chris Freeman
Chris Freeman
Treehouse Moderator 68,457 Points

You code looks correct. Perhaps start a new post with more details including all of the code and the error you are seeing.