[Django]-Django template display item value or empty string

319👍

You want the default_if_none template filter, (doc).

default_if_none will display the given string if the variable is ‘None’.

default will display the string if the variable evaluates to False, ie empty strings, empty lists etc

{{ item.somefield|default_if_none:"" }}
{{ item.somefield|default:"" }}

14👍

{{ item.somefield|default_if_none:"" }}
👤matino

Leave a comment