Creating our homepage template

Let's now look at the HTML required for our template. Let's start by creating a new directory next to our dependencies, titled templates.

Inside our new directory, create the following home.html file:

<!DOCTYPE html> 
 
<body> 
    {% if messages %} 
        {% for message in messages %} 
            <p>{{ message['message'] }}</p> 
        {% endfor %} 
    {% else %} 
        <p>No messages!</p> 
    {% endif %} 
</body> 

This HTML is nothing fancy, and neither is the templating logic! If you are unfamiliar to Jinja2 or Django templating then you're probably thinking that this HTML looks weird with the curly braces everywhere. Jinja2 uses these to allow us to input Python-like syntax into our template.

In the preceding example, we start off with an if statement to ...

Get Python Programming Blueprints now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.