Loading lesson path
Concept visual
Start at both ends
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 %}Formula
< h1 > Hello </h1 >{% else %}Formula
< h1 > Bye </h1 >{% endif %}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.
Formula
templates/template.html<ul>
{% for x in mymembers %}<li></li>
{% endfor %}</ul> In the next chapters you will learn about the most common template tags.
A list of all template tags:
Specifies if autoescape mode is on or off block
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
Used in for loops. Outputs a block only if a value has changed since the last iteration include
Used in cycles. Resets the cycle spaceless
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