I am trying to use a relatively simple if elif statement within a for loop, but it seems to throw an error. This is the syntax that I am using

{% for ruleset in rulesets %}
<!-- some simple html / template tags come here -->
{% for rule in rules %}
  {% if rule.0 = ruleset.0 and rule.2 = 1 %}
    {{ rule.1 }}: {{ rule.3 }} out of {{ rule.4 }} points above {{ rule.5 }} sigma
  {% elif rule.0 = ruleset.0 and rule.2 = 2 %}
    {{ rule.1 }}: {{ rule.3 }} out of {{ rule.4 }} points below {{ rule.5 }} sigma
  {% endif %}
{% endfor %}
{% endfor %}

There are a few more rules that I will want to incorporate, so I can't just use the else tag.

The error I am getting is: TemplateSyntaxError: Invalid block tag: 'elif', expected 'else' or 'endif'

Any suggestions as to how to solve this? I was using nested if clauses at some point too, but was getting similar errors.

有帮助吗?

解决方案

elif is supported since django 1.4

it may be that you are using an older version of django.

see my comment regarding the = sign that is supposed to be == to evaluate to True or False as expected. Or you can use the ifequal template tag instead.

其他提示

The elif statement was added to Django in version 1.4 (Django 1.4 release notes).

If you are using an older Django version you will either have to upgrade to a newer version or use nested if/else statements.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top