Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/OpenClassrooms-Student-Center/Python-OC-Lettings-FR/llms.txt

Use this file to discover all available pages before exploring further.

Orange County Lettings uses Django’s template engine with six HTML templates stored in the /templates/ directory. All pages extend base.html, which provides the shared navbar, footer, and static file loading.

Template inheritance

Every page template starts with {% extends "base.html" %} and fills in two named blocks defined by the base layout:
  • {% block title %} — sets the <title> element in <head>.
  • {% block content %} — renders the main page body between the navbar and footer.

base.html — Master layout

base.html is the root template from which all other templates inherit.
<!DOCTYPE html>
{% load static %}

<html lang="en">
    <head>
        ...
        <title>{% block title %}{% endblock title %}</title>
        <link href="{% static 'css/styles.css' %}" rel="stylesheet" />
        <link rel="stylesheet" href="https://unpkg.com/aos@next/dist/aos.css" />
    </head>
    <body>
        <nav class="navbar navbar-expand-lg bg-white navbar-light">
            <div class="container">
                <a class="navbar-brand" href="{% url 'index' %}">...</a>
                <a class="btn btn-primary" href="{% url 'profiles_index' %}">Profiles</a>
                <a class="btn btn-primary" href="{% url 'lettings_index' %}">Lettings</a>
            </div>
        </nav>

        {% block content %}{% endblock %}

        <footer class="footer bg-dark footer-dark">
            <div>Copyright &copy; Orange County Lettings 2023</div>
        </footer>

        <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
        <script src="https://unpkg.com/aos@next/dist/aos.js"></script>
    </body>
</html>
Key features of base.html:
  • Loads static files with {% load static %} and references local CSS and the site logo via {% static %}.
  • Includes Bootstrap 5.1.3 from CDN for layout and component styling.
  • Includes the AOS (Animate On Scroll) library, initialised with duration: 600 and once: true.
  • Navbar contains named-URL links to the Profiles and Lettings index pages.
  • Footer displays the copyright notice: “Orange County Lettings 2023”.
  • Defines {% block title %} and {% block content %} for child templates to override.

index.html — Home page

{% extends "base.html" %}
{% block title %}Holiday Homes{% endblock title %}

{% block content %}
<h1>Welcome to Holiday Homes</h1>
<a href="{% url 'profiles_index' %}">Profiles</a>
<a href="{% url 'lettings_index' %}">Lettings</a>
{% endblock %}
  • Extends base.html.
  • Sets the page title to "Holiday Homes".
  • Displays a "Welcome to Holiday Homes" heading.
  • Renders two call-to-action buttons linking to the Profiles and Lettings index pages.
  • Receives no context variables from the view — views.index calls render(request, 'index.html') with no context.

lettings_index.html — Lettings list

{% extends "base.html" %}
{% block title %}Lettings{% endblock title %}

{% block content %}
{% if lettings_list %}
    <ul>
        {% for letting in lettings_list %}
            <li><a href="{% url 'letting' letting_id=letting.id %}">{{ letting.title }}</a></li>
        {% endfor %}
    </ul>
{% else %}
    <p>No lettings are available.</p>
{% endif %}
{% endblock %}
  • Extends base.html.
  • Renders the lettings_list context variable — a queryset of all Letting objects.
  • Iterates over the list; each item links to its detail page using {% url 'letting' letting_id=letting.id %}.
  • Displays "No lettings are available." when the queryset is empty.

letting.html — Letting detail

{% extends "base.html" %}
{% block title %}{{ title }}{% endblock title %}

{% block content %}
<h1>{{ title }}</h1>
<p>{{ address.number }} {{ address.street }}</p>
<p>{{ address.city }}, {{ address.state }} {{ address.zip_code }}</p>
<p>{{ address.country_iso_code }}</p>
{% endblock %}
  • Extends base.html.
  • Uses the title context variable for both the <title> element and the page heading.
  • Uses the address context variable to display all address fields: number, street, city, state, zip code, and country ISO code.

profiles_index.html — Profiles list

{% extends "base.html" %}
{% block title %}Profiles{% endblock title %}

{% block content %}
{% if profiles_list %}
    <ul>
        {% for profile in profiles_list %}
            <li><a href="{% url 'profile' username=profile.user.username %}">{{ profile.user.username }}</a></li>
        {% endfor %}
    </ul>
{% else %}
    <p>No profiles are available.</p>
{% endif %}
{% endblock %}
  • Extends base.html.
  • Renders the profiles_list context variable — a queryset of all Profile objects.
  • Each item links to the profile detail page using {% url 'profile' username=profile.user.username %}.
  • Displays "No profiles are available." when the queryset is empty.

profile.html — Profile detail

{% extends "base.html" %}
{% block title %}{{ profile.user.username }}{% endblock title %}

{% block content %}
<h1>{{ profile.user.username }}</h1>
<p><strong>First name:</strong> {{ profile.user.first_name }}</p>
<p><strong>Last name:</strong> {{ profile.user.last_name }}</p>
<p><strong>Email:</strong> {{ profile.user.email }}</p>
<p><strong>Favorite city:</strong> {{ profile.favorite_city }}</p>
{% endblock %}
  • Extends base.html.
  • Uses {{ profile.user.username }} for both the page title and the heading.
  • Displays fields from both the Profile model (favorite_city) and the related Django User model (first_name, last_name, email).

Context variables: views to templates

Each view constructs a context dictionary and passes it to render(). Template variables map directly to dictionary keys.
def letting(request, letting_id):
    letting = Letting.objects.get(id=letting_id)
    context = {
        'title': letting.title,
        'address': letting.address,
    }
    return render(request, 'letting.html', context)
In letting.html, {{ title }} resolves to letting.title and {{ address.number }} resolves to letting.address.number — Django’s template engine traverses attribute lookups automatically. The table below summarises the context variables provided by each view:
TemplateViewContext variables
index.htmlviews.index(none)
lettings_index.htmlviews.lettings_indexlettings_list — queryset of all Letting objects
letting.htmlviews.lettingtitle — the letting’s title; address — the linked Address object
profiles_index.htmlviews.profiles_indexprofiles_list — queryset of all Profile objects
profile.htmlviews.profileprofile — the matched Profile object (with related user)

Build docs developers (and LLMs) love