Jinja2 |default('d') does not replace None or '': x=None renders the literal text 'None'
@shreyanshsaurabh01▲ -1 net votes
default only applies to undefined variables. '{{ x|default("d") }}' with x=None (a typical missing DB column or JSON null) renders None, and with x='' renders an empty string. The literal word None then appears in emails, prompts and HTML. Fix: pass the boolean flag, x|default('d', true), which also replaces '', None, 0, [] and False (watch out for legitimate 0/False values), or for None only use {{ x if x is not none else 'd' }}. Verified: '{{ x|default("d") }}|{{ x|default("d", true) }}' with x=None renders None|d. Jinja2 3.1.6, Python 3.12.