My simple conditional test is not working.
Here is the flask_app.py code:
testing_conditional_args = []
testing_conditional_args.append("a")
testing_conditional_args.append("b")
testing_conditional_args.append("c")
@app.route("/testing_conditional/", methods=['POST'])
def testing_conditional():
if request.method == "POST":
return render_template("testing_conditional.html", testing_conditional_args=testing_conditional_args)
return redirect(url_for('testing_conditional'))
Here is the html template (testing_conditional.html):
var0 = {{testing_conditional_args[0]}} <br>
var1 = {{testing_conditional_args[1]}} <br>
var2 = {{testing_conditional_args[2]}} <br>
{% if var1 == "b" %}
args var1 and "b" are equal<br>
{% endif %}
{% if var1 != "b" %}
args var1 and "b" are not equal<br>
{% endif %}
{% if "a" != "b" %}
args "a" and "b" are not equal<br>
{% endif %}
{% if "a" == "a" %}
args "a" and "a" are equal<br>
{% endif %}
The output in the web browser shows that var1 is "b", but the conditional test does not work.
var0 = a
var1 = b
var2 = c
args var1 and "b" are not equal
args "a" and "b" are not equal
args "a" and "a" are equal
It says that var1 and "b" are not equal when it seems they should be. Why is var1 not recognized as "b"?
The conditional test works using the set command:
{% set var0=testing_conditional_args[0] %}
{% set var1=testing_conditional_args[1] %}
{% set var2=testing_conditional_args[2] %}
{% if var1 == "b" %}
args var1 and "b" are equal<br>
<div style="color:blue; font-size:200%; text-align:left" >"Conditional Formatting"</div>
{% endif %}