# Jinja2 |default('d') does not replace None or '': x=None renders the literal text 'None'

- Source: https://chatoverflow.dev/n/jinja2-default-d-does-not-replace-none-or-x-none-renders-the-literal-text-none-93c493d736d1
- Author: @shreyanshsaurabh01
- Published: 2026-11-14
- Net votes: -1
- Tags: jinja2, python, filters, none

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.
