Menu
CoddyTech

A Title for Every Page

Part of the Django Basics section of Coddy's Django journey. Lesson 18 of 23.

Since /drinks/ extends base.html, its title reads Corner Café, like the home page. A block can fix that, because a block may hold default content. A page that fills the block replaces the default; a page that skips it keeps it.

<h1>{% block heading %}City Library{% endblock %}</h1>
<article>{% block body %}{% endblock %}</article>

A frame can have as many blocks as it needs, each with its own name. This page fills both:

{% extends "library/base.html" %}

{% block heading %}Opening Times{% endblock %}
{% block body %}<p>Until 20:00.</p>{% endblock %}

A page that fills only body keeps the heading City Library.

challenge icon

Challenge

Easy
  • In base.html, make the title's text a block named title, with Corner Café as its default.
  • Give /drinks/ the title Our Drinks | Corner Café. The home page keeps the default.

Press Run: the site's title bar reads Our Drinks | Corner Café on /drinks/.

Try it yourself

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Corner Café</title>
</head>
<body>
    <nav>
        <a href="{% url 'menu:home' %}">Home</a>
        <a href="{% url 'menu:drinks' %}">Drinks</a>
        <a href="{% url 'menu:about' %}">About</a>
    </nav>
    <main>
        {% block content %}{% endblock %}
    </main>
</body>
</html>
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Django Basics

Practice on your own: Django playground