The Template represents the presentation layer (T in MVT) of a Django application. The Django Template Language (DTL) is designed to let backend engineers and frontend designers collaborate seamlessly without introducing security vulnerabilities or business logic clutter into markup.
| Syntax Pattern | Code Example | Description & Behavior |
|---|---|---|
| Variables | {{ post.title }} |
Outputs the value of a variable or dictionary lookup passed from the view context. |
| Tags | {% for post in posts %} ... {% endfor %} |
Controls rendering logic: loops, conditional branches, URL lookups, and block extensions. |
| Filters | {{ post.content|truncatewords:30 }} |
Transforms the visual presentation of a variable before it is rendered to HTML. |
| Comments | {# Single line #} or {% comment %} |
Internal developer notes that are never output to the final HTML delivered to browsers. |
Here is a production-grade base.html skeleton declaring blocks for metadata, styles, content, and scripts:
<!-- templates/base.html -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{% block title %}Veewom Tutorials{% endblock %}</title>
<link rel="stylesheet" href="{% static 'css/bootstrap.min.css' %}">
{% block extra_css %}{% endblock %}
</head>
<body>
<nav class="navbar navbar-default">
<!-- Global Navigation bar content -->
</nav>
<main class="container">
<!-- Child templates inject their unique content here -->
{% block content %}
{% endblock %}
</main>
<footer class="footer">
<p>© 2016-2026 Veewom.com</p>
</footer>
<script src="{% static 'js/bootstrap.min.js' %}"></script>
{% block extra_js %}{% endblock %}
</body>
</html>
And here is how a child template inherits the layout and overrides only the content:
<!-- templates/blog/post_detail.html -->
{% extends "base.html" %}
{% block title %}{{ post.title }} | Veewom{% endblock %}
{% block content %}
<article class="article-wrapper">
<h1>{{ post.title }}</h1>
<p class="text-muted">Published by {{ post.author }} on {{ post.created_at|date:"F j, Y" }}</p>
<div class="article-body">
{{ post.content|linebreaks }}
</div>
</article>
{% endblock %}
The {% extends 'base.html' %} tag MUST be the very first line of any child template. Putting HTML tags or spaces before {% extends %} causes Django to throw a TemplateSyntaxError.
Broaden your backend architecture, REST API design, and production engineering expertise:
Format dates, truncate text, and author custom template logic.
Link CSS, JS, and image assets into base template layouts.
Inject site-wide global variables directly into every template.
Combine Django templates with modern responsive frontend frameworks.