Django templates allow you to inject dynamic content and manage logic directly in HTML using variables, filters, and template tags like for, if, and include.
// Displaying template variables
<h1>Welcome, {{ user_name }}!</h1>
<p>You have {{ num_messages }} new messages.</p>
// Applying Django template filters
{{ user_name|lower }}
{{ current_date|date:"F j, Y" }}
{{ user_profile|default:"Profile not available" }}
// Looping with for tag
{% for message in messages %}
<p>{{ message }}</p>
{% endfor %}
// Conditional rendering with if tag
{% if user_is_authenticated %}
<p>Welcome back, {{ user_name }}!</p>
{% else %}
<p>Please log in.</p>
{% endif %}
// Including reusable templates
{% include "header.html" %}
Templates dynamically replace placeholders with real data passed from Django views, allowing HTML to respond intelligently to application state.
User is not authenticated
Modify the values below to see how Django syntax renders them.
for