Python Flask Basics Templates and Static Files Template Inheritance

Flask Blocks

Can't figure out what's wrong with the code. The error message is extremely vague. "index.html" seems to have wrong content in it.

Thanks in advance!

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

1 Answer

Andreas cormack
Andreas cormack
Python Web Development Techdegree Graduate 28,388 Points

Hi Rwiddhi

Looks like you are missing the <h1> tag from your index.html page. See below of what it should contain

{% extends "layout.html" %}
{% block title %}{{super()}} Homepage{% endblock %}
{%block content %}
    <h1>Smells Like Bakin'!</h1>
    <p>Welcome to my bakery web site!</p>
{%endblock%}