How do I persuade Jinja2 to not print "None"
when the value is None
?
I have a number of entries in a dictionary and I would like to output everything in a single loop instead of having special cases for different keywords. If I have a value of None
(the NoneType
not the string) then the string "None"
is inserted into the template rendering results.
Trying to suppress it using
{{ value or '' }}
works too well as it will replace the numeric value zero as well.
Do I need to filter the dictionary before passing it to Jinja2 for rendering?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…