Outputs default
if and only if the value is None
.
Variables
a = None b = 0 c = '' d = False e = []
Template
<ol> <li>{{ a|default_if_none:"No a" }}</li> <li>{{ b|default_if_none:"No b" }}</li> <li>{{ c|default_if_none:"No c" }}</li> <li>{{ d|default_if_none:"No d" }}</li> <li>{{ e|default_if_none:"No e" }}</li> </ol>
Result
<ol> <li>No a</li> <li>0</li> <li></li> <li>False</li> <li>[]</li> </ol>
Notice that the default is only used for a
. While all the rest evaluate to False
, they are not None
.