Tutorials References Exercises Videos Menu
Create Website Get Certified Upgrade

Template Filter - default_if_none


Example

Write color names, but wite "nocolor" if the value is None:

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

Definition and Usage

The default_if_none filter allows you to specify a default value to use if the value is None.

The value has to be exactly None for this filter to have effect.


Syntax

{{ value|default_if_none: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.


Arguments

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