Syntax and Filters
Two kinds of marker. {{ }} prints a value. {% %} is a tag that does something: a loop, a condition, extending a layout.
A filter transforms a value on the way out: {{ post.created|date:"j F Y" }}.
Templates are deliberately limited. You cannot call a function with arguments. You cannot do arbitrary Python.
This is not an oversight. It is a boundary: logic belongs in the view, where it can be read, reused and tested. When you find yourself fighting the template language, the answer is almost always to compute the value in the view and pass it in.
✦ {% empty %} exists and people miss it
A for loop can carry an {% empty %} block that renders when there is nothing to loop over. It saves a separate if, and it means the empty case is written right next to the loop where it will actually be maintained.
Mark this lesson complete
Signed in, your progress follows you to every device.