🔥Limited Offer: Get 50% OFFon AI & Full Stack Courses🔥
Back to Django Notes
Topic #30

Django Tags


Template Tags

In Django templates, you can perform programming logic like executing if statements and for loops.

These keywords, if and for, are called "template tags" in Django.

To execute template tags, we surround them in {% %} brackets.

Example

{% if greeting == 1 %}
  <h1>Hello</h1>
{% else %}
  <h1>Bye</h1>
{% endif %}

Django Code

The template tags are a way of telling Django that here comes something else than plain HTML.

The template tags allows us to to do some programming on the server before sending HTML to the client.

<ul>
  {% for x in mymembers %}
    <li>{{ x.firstname }}</li>
  {% endfor %}
</ul>

In the next chapters you will learn about the most common template tags.


Tag Reference

A list of all template tags:

Tag Description
autoescape Specifies if autoescape mode is on or off
block Specifies a block section
comment Specifies a comment section
csrf_token Protects forms from Cross Site Request Forgeries
cycle Specifies content to use in each cycle of a loop
debug Specifies debugging information
extends Specifies a parent template
filter Filters content before returning it
firstof Returns the first not empty variable
for Specifies a for loop
if Specifies a if statement
ifchanged Used in for loops. Outputs a block only if a value has changed since the last iteration
include Specifies included content/template
load Loads template tags from another library
lorem Outputs random text
now Outputs the current date/time
regroup Sorts an object by a group
resetcycle Used in cycles. Resets the cycle
spaceless Removes whitespace between HTML tags
templatetag Outputs a specified template tag
url Returns the absolute URL part of a URL
verbatim Specifies contents that should not be rendered by the template engine
widthratio Calculates a width value based on the ratio between a given value and a max value
with Specifies a variable to use in the block

Want to go beyond the notes?

Join CodingNow 2.0's Django course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

Django Tags – FAQs

Quick answers about learning Django Tags in Django.

This free note from CodingNow 2.0 explains Django Tags in Django — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every Django topic on CodingNow 2.0, including Django Tags, is 100% free with no signup required.
With focused practice, most students grasp Django Tags in 1–3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) — expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now