📝 Django

Template Loading in Django

P
Author
Pyland
📅
Published
30.06.2026
⏱️
Reading time
1 min
👁️
Views
80
🌿
Level
Medium

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

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/
return render(request, 'tasks/list.html', context)
return render(request, 'base.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

📝

pytest-django: Testing Django

Охватываемые темы: Installation, @pytest.mark.djangodb, Fixtures, Testing views.

📅 30.06.2026 👁️ 132
📝

Django: Template Tags

Template tags are logic inside HTML. Unlike {{ variable }} which only outputs a value,...

📅 30.06.2026 👁️ 85
📝

Django: Static Files

Static files are CSS, JavaScript, images, and fonts. Django handles them in a specific way:...

📅 30.06.2026 👁️ 73

Did you like the article?

Subscribe to our updates and receive new articles first. Grow with PyLand!