Reputation: 511
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.
Upvotes: 0
Views: 512
Reputation: 2071
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.
Upvotes: 1
Reputation: 2790
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.
Upvotes: 2