回答:
Jinja2 テンプレートデザイナーのドキュメントから:
{% if variable is defined %}
value of variable: {{ variable }}
{% else %}
variable is not defined
{% endif %}
{% if variable is not defined %}して逆をテストできます。
{% if variable is defined and variable %}空性もチェックします
{% if variable is defined %}変数がの場合、trueです None。
not is None許可されていないので、
{% if variable != None %}
本当にあなたの唯一のオプションです。
variable常にに評価されTrueていないなし、とき{% if variable != None %}と同等ではありません{% if variable %}。
None小文字の使用を確認する場合none {% if variable is not none %}
次のように、jinja2テンプレートで変数を定義することもできます。
{% if step is not defined %}
{% set step = 1 %}
{% endif %}
そして、あなたはこのようにそれを使うことができます:
{% if step == 1 %}
<div class="col-xs-3 bs-wizard-step active">
{% elif step > 1 %}
<div class="col-xs-3 bs-wizard-step complete">
{% else %}
<div class="col-xs-3 bs-wizard-step disabled">
{% endif %}
それ以外の場合(あなたがを使用しない場合{% set step = 1 %})、上のコードがスローします。
UndefinedError: 'step' is undefined