Template Syntax in Python

From the Django cheat sheet · Templates · verified Jul 2026

Template Syntax

Django template language basics

html
<!-- Variables -->
{{ product.name }}
{{ product.price|floatformat:2 }}

<!-- Tags -->
{% if product.in_stock %}
  <p>Available</p>
{% endif %}

{% for product in products %}
  {{ product.name }}
{% endfor %}
💡 Use |default filter for None values
📌 {% empty %} handles empty loops
⚡ Template inheritance with extends
🟢 Always {% load static %} for static files
Back to the full Django cheat sheet