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 with SQLAlchemy Basics Creating a Basic Website with Flask Template Inheritance

Hi could you please urgently help me pass this task, i'm struggling to understand how to add the link properly

Especially in layout.html. Your help would be much appreciated.

index.html
{% extends "layout.html" %}
<a href="http://Contact.com">anchored text</a>
layout.html
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta name="description" content="Treehouse code chalenge practice.">
        <meta name="viewport" content="width=device-width, initial-scale=1">
    </head>
    <body>
        <h1>Practice Template Inheritance</h1>
        {% block link %}<a href="http://Contact.com">anchored text</a>{% endblock %}
    </body>
</html>

3 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,423 Points

Hey Danielle Murray, you are not far off.

From index.html, blocks of code are used to replaced the corresponding block in the extend template, in this case, layout.html. Any named block layout.html that is also in index.html will be replaced with the index.html content.

So to replace the `{% block link %}{% endblock %} in layout.html, you need the same tags in index.html. In between these tags in index.html add the desired link.

Note the href="" location should not contain text, and the anchored text, in this case Contact, goes between the HTML tags <a href=""> and </a>.

In tasks 1 and 2, the file layout.html does not need to be altered.

Post back if you need more help. Good luck!

Chris Freeman
Chris Freeman
Treehouse Moderator 68,423 Points

Also note, the challenge checker expects the template tags {% %} within index.html to be on separate lines.

I've flagged this as a bug, but it might be a while before it is fixed.

Hi Chris Freeman I changed my code to:-

{% extends "layout.html" %}
{% block link %}<a href="https://example.com">Contact</a>{% endblock %}

and I left layout.html as is put it still is not passing, what is my mistake?

Chris Freeman
Chris Freeman
Treehouse Moderator 68,423 Points

The checker for this challenge is very picky. Your code is correct for Task 2, but the checker wants:

  • nothing between the quotes in href=""
  • The {% block link %} and {% endblock %} tags needs to be on their own separate lines. That is, there should be four lines of code including the extends line.

Chris Freeman This is my revised code:-

{% extends "layout.html" %}
<a>href="">Contact</a>
{% block link %}{% endblock %}

But it still doesn't pass

[MOD: added ```python formatting -cf]

Chris Freeman
Chris Freeman
Treehouse Moderator 68,423 Points

Very close! All the bits are there. The line order is incorrect: it should be:

{% extends ...
{% block link...
<a>href=“”...
{% endblock ...

(sorry, partial lines used to prevent cut-and-paste use)

Chris Freeman This is my revised code:-

{% extends "layout.html" %} <a>href="">Contact</a> {% block link %}{% endblock %}

But it still doesn't pass