Python Flask Basics Templates and Static Files Template Inheritance

Sam Akers
Sam Akers
4,744 Points

Can't extend "layout.html"

For some reason I can only see "Hello from Sam" printed on the page.

"Brought to you by the fine folks at Treehouse!" does not render at all.

Within the templates folder I have add.html ,index.html and layout.html

Outwith this folder is app_flask.py

index.html

{% extends "layout.html" %}

{% block title %}Howdy!{% endblock %}

{% block content %}
<h1>Hello from {{ name }}!</h1>
{% endblock %}

layout.html

<!DOCTYPE html>
<html>
  <head>
    <title>{% block title %}{% endblock %}</title>
  </head>
  <body>
    {% block content %}{% endblock %}
    <p>Brought to you by the fine folks at Treehouse!</p>
  </body>
</html>
Josh Stephens
Josh Stephens
11,474 Points

Copied your you files exactly as you have typed and I seem to get a different result. With that in mind I think your code is probably correct, which leads me to think that you should try one of the two things first

  1. Copy the code from here and save each file and then reload if you are still running app.py or
  2. Restart your dev server (which is just CTRL + C) and then run python app.py again