Django·Django from project to API

Templates

Render data with the Django template language and template inheritance.

Intermediate 12 min read Lesson 3 of 300 Challenge included
What you will be able to do
  • Use {{ value }} for output and {% tag %} for logic.
  • Extend a base template with blocks.
  • Autoescaping is on by default.
  • Avoid heavy logic in templates.

In plain English

Django templates are HTML with a small, deliberately limited language. Inheritance keeps layout in base.html and lets pages fill blocks. Autoescaping protects you from injected HTML; use |safe only for trusted content.

lessons/detail.htmlHTML
{% extends "base.html" %}

{% block content %}
  <h1>{{ lesson.title }}</h1>
  <p>{{ lesson.summary }}</p>
  {% if lesson.minutes >= 15 %}
    <span class="badge">Long lesson</span>
  {% endif %}
{% endblock %}
Your turn

Show an empty state

Easy

Render a paragraph when the lessons list is empty.

HTML · starter
{% for lesson in lessons %}
Check your understanding before moving on.
Knowledge checkQuestion 1

Is autoescaping enabled by default in Django templates?

Select an answer to continue
Study tools

Make it yours.

Keep a private note for this lesson, then turn the key ideas into flashcards you can revisit.

Sign in to save notes and flashcards.Both are private to your account and stay with your progress.
Sign in
Finished reading?

Lock in what you just learned.

Mark this lesson complete to save your place and move one step closer to the certificate.

Next: Models and migrations
Lesson 3 of 300 · 0% of course