Search⌘ K

Filters and Comments

Understand how to apply built-in filters to modify variable output and use comments to document or disable parts of Django templates. This lesson helps you enhance template flexibility and maintainability by mastering filters like default, length, and lower, along with proper comment syntax.

Filters

Filters are used to modify variables for display.

Syntax

Below is the syntax of the filter:

{{ variable | filter_name }}

A | (called a pipe) is used to apply a filter. Basically, the syntax above will display the value of the {{variable}} after being filtered through the filter_name filter.

Some filters can also take arguments. A filter argument looks like this: {{ bio|truncatewords:30 }}. This will display the first 30 words of the ...