In Jinja2, how do you test if a variable is undefined?

后端 未结 6 1751
小蘑菇
小蘑菇 2020-12-07 11:54

Converting from Django, I\'m used to doing something like this:

{% if not var1 %} {% endif %}

and having it work if I didn\'t put var1 into

6条回答
  •  伪装坚强ぢ
    2020-12-07 12:13

    {% if variable is defined %} is true if the variable is None.

    Since not is None is not allowed, that means that

    {% if variable != None %}

    is really your only option.

提交回复
热议问题