Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Flask with SQLAlchemy Basics Creating a Basic Website with Flask Template Inheritance

Danielle Murray
seal-mask
.a{fill-rule:evenodd;}techdegree
Danielle Murray
Python Development Techdegree Student 4,494 Points

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 67,638 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 67,638 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.

Danielle Murray
seal-mask
.a{fill-rule:evenodd;}techdegree
Danielle Murray
Python Development Techdegree Student 4,494 Points

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 67,638 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.
Danielle Murray
seal-mask
.a{fill-rule:evenodd;}techdegree
Danielle Murray
Python Development Techdegree Student 4,494 Points

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 67,638 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)

Danielle Murray
seal-mask
.a{fill-rule:evenodd;}techdegree
Danielle Murray
Python Development Techdegree Student 4,494 Points

Chris Freeman This is my revised code:-

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

But it still doesn't pass