Understanding the Django Template Language (DTL) is important to create Django templates. It serves as a bridge between HTML and Python code, especially for views.py. Using DTL, you can embed variables passed by views.py or add simple logic in an HTML template file.
You can display data (objects) passed by views.py using this format.
Using the filter, you can modify variables for display. For example:
{{ name:lower }}
displays the value of the {{ name }}
variable in lowercase text{{ name|truncatewords:n }}
displays the first n words of the {{ name }}
variable{{ text|linebreaks }}
converts line breaks in {{ text }}
variable to <p>
tag{{ name:default:"default data" }}
displays when the {{ name }}
variable is false or emptyUsing this format, you can apply simple logic e.g., for..
, if...else
.
Using this format, you can add comments. The comments won't be displayed in browsers.
Django documentation reference: The Django template language
Understanding the Django Template Language (DTL) is important to create Django templates. It serves as a bridge between HTML and Python code, especially for views.py. Using DTL, you can embed variables passed by views.py or add simple logic in an HTML template file.
You can display data (objects) passed by views.py using this format.
Using the filter, you can modify variables for display. For example:
{{ name:lower }}
displays the value of the {{ name }}
variable in lowercase text{{ name|truncatewords:n }}
displays the first n words of the {{ name }}
variable{{ text|linebreaks }}
converts line breaks in {{ text }}
variable to <p>
tag{{ name:default:"default data" }}
displays when the {{ name }}
variable is false or emptyUsing this format, you can apply simple logic e.g., for..
, if...else
.
Using this format, you can add comments. The comments won't be displayed in browsers.
Django documentation reference: The Django template language