Templates are usually used to generate HTML, but Django templates can also generate any document based on text format.
The text enclosed in two braces (for example, {person_name}) is called a variable ).
The text enclosed by braces and percent signs (for example, {% if ordered_warranty %}) is a template tag ). Tags are clearly defined, that is, labels that only notify the template system to complete some work.
The template in this example contains a for tag ({% for item in item_list %}) and an if tag ({% if ordered_warranty % })
The for tag is similar to the for statement in Python, allowing you to access every project in the sequence cyclically. The IF tag, as expected, is used to perform logical judgment. Here, the tag label checks whether the value of ordered_warranty is true. If yes, the template System Displays content between {% ifordered_warranty %} and {% else %}; otherwise, content between {% else %} and {% endif %} is displayed. {% Else %} is optional.
Finally, the second section of the template contains an example of the filter, which is the most convenient way to convert the variable output format. For example, {ship_date | Date: "f j, Y"} in this example, we pass the variable ship_date to the date filter and specify the parameter "F ".J, y ". The date filter outputs the format based on parameters.
DJANGO: Template