So I want to show in a jinja2 template whether a state is True
, False
or None
.
Naturally I use a boolean since I have there the three states I need.
So I tried the following code to show the True
and the False
state and wanted to show nothing when it's None
.
{% if valid %}
VALID
{% elif not valid %}
NOT VALID
{%endif %}
But my problem is now that when valid
is None
it shows 'NOT VALID'
How I can change that to showing nothing instead.
Write if valid is none
. Note that is
in Jinja is not the same as Python's is
. In this case is
calls a Jinja filter named none
. Here is the list of built-in filters.
jinja2.Template('{% if a is none %}None{% endif %}').render(a=None)
u'None'
jinja2.Template('{% if a is none %}None{% endif %}').render(a=False)
u''
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With