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

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

{% extends ...
{% block ...
<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,031 Points

Chris Freeman This is my revised code:-

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

But it still doesn't pass