Tutorials References Exercises Bootcamp Menu
Sign Up Create Website Get Certified Pro

Template Filter - default


Write color names, but write "nocolor" if the value is empty:

{% for x in colors %}
  <h1>{{ x|default:"nocolor" }}</h1>
{% endfor %}
Run Example »

Definition and Usage

The default filter allows you to specify a default value to use if the value evaluates to False.

Values that evaluates to False are:

  • Empty Strings ""
  • Any numeric 0
  • Any empty object [], (), {}, set(), range(0)
  • None
  • False


{{ value|default:defaultvalue }}

Template filters are defined by using a pipe | character followed by the name of the filter.

Arguments are defined by using a colon : character followed by the argument value.


Value Description
defaultvalue Required. The value to return if the value is False.