bugl
bugl
HomeLearnPatternsPathsSearchPremium
HomeLearnPatternsPaths
Learn/Django/Django Syntax
Django•Django Syntax

Django Template 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

templates/template.html :

{% 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.

templates/template.html :

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

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

Previous

Django Template Variables

Next

Django if Tag

This chapter

Overview
6

Lessons

16m

Read time

1. Django Template Variables2. Django Template Tags3. Django if Tag4. Django for Tag5. Django comment Tag6. Django include Tag

On this page

Template TagsDjango Code