๐Ÿ“ Django

Template Loading in Django

P
Author
PyLand Team
๐Ÿ“…
Published
30.06.2026
โฑ๏ธ
Reading time
1 min
๐Ÿ‘๏ธ
Views
270
๐ŸŒฟ
Level
Medium

Django searches the configured project and application directories for templates, so directory structure determines how reliably they are resolved.

Configuring Template Discovery

# settings.py
TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [BASE_DIR / 'templates'],  # project-level template directory
        'APP_DIRS': True,  # search in <app>/templates/ for each application
        'OPTIONS': {
            'context_processors': [...],
        },
    },
]

Directory Structure

mysite/
โ”œโ”€โ”€ templates/          # DIRS โ€” shared templates
โ”‚   โ””โ”€โ”€ base.html
โ”œโ”€โ”€ tasks/
โ”‚   โ””โ”€โ”€ templates/      # APP_DIRS โ€” application templates
โ”‚       โ””โ”€โ”€ tasks/
โ”‚           โ”œโ”€โ”€ list.html
โ”‚           โ””โ”€โ”€ detail.html

Recommended: use tasks/templates/tasks/ to avoid name conflicts between applications.

Using Templates in a View

# Path relative to DIRS or app/templates/
def task_list(request):
    context = {'tasks': Task.objects.all()}
    return render(request, 'tasks/list.html', context)

Template Inheritance

<!-- templates/base.html -->
<!DOCTYPE html>
<html>
<head><title>{% block title %}Site{% endblock %}</title></head>
<body>
  {% block content %}{% endblock %}
</body>
</html>
<!-- tasks/templates/tasks/list.html -->
{% extends 'base.html' %}

{% block title %}Tasks{% endblock %}

{% block content %}
  <h1>Task List</h1>
{% endblock %}

include โ€” Inserting Fragments

<!-- Insert another template -->
{% include 'partials/task_card.html' with task=task %}

<!-- tasks/templates/partials/task_card.html -->
<div class="card">
  <h3>{{ task.title }}</h3>
  <span>{{ task.get_status_display }}</span>
</div>

Debugging Template Loading

# If a template is not found, Django raises TemplateDoesNotExist
# and lists all paths that were searched

With DEBUG=True, the error page shows the full search list.

Your reaction to the article

๐Ÿ’ฌ Comments (0)

๐Ÿ” Sign in to leave a comment
๐Ÿšช Login
๐Ÿ’ญ

No comments yet

Be the first to share your opinion about this article!

๐Ÿ”— Similar

Similar articles

Continue learning with these materials

๐Ÿ“

Search in Django

You can start with simple Django ORM filters and move to PostgreSQL features when you...

๐Ÿ“… 30.06.2026 ๐Ÿ‘๏ธ 277
๐Ÿ“

Swagger Documentation with drf-spectacular

drf-spectacular generates an OpenAPI 3.0 schema and Swagger UI for DRF.

๐Ÿ“… 30.06.2026 ๐Ÿ‘๏ธ 561
๐Ÿ“

settings.py: Django Configuration

settings.py is the central configuration file for a Django project.

๐Ÿ“… 30.06.2026 ๐Ÿ‘๏ธ 314
๐ŸŽ“ Continue learning

Courses that cover this material

Visit the course to apply this material in practice.

Django RequestLab: from HTTP to secure production Open course curriculum