36

私が作成したテンプレート ファイルには、次のものが含まれています。

{% if type({'a':1,'b':2}) is dict %}
    print "Oh Yes!!"
{% else %}
    print "Oh No!!!"
{% endif %}

すると、Jinja2 は次のように応答します。

TemplateAssertionError: no test named 'dict'

私はJinja2とFlaskがまったく初めてです

4

3 に答える 3

11

カスタム タイプを取得する場合は、次の例のようにフィールド名にアクセスできます。

  {% if 'RelationField' in field.__class__.__name__ %}
      <div class="col-md-1">
      Manage object
      </div>
  {% endif %}
于 2016-06-28T21:29:59.533 に答える