[英]Jinja2 for loop in javascript on a list not working but accessing individual elements works
[英]Jinja2 UndefinedError accessing specific elements of a list
在我的 python Flask 代码中,我在会话中存储了一个数字列表并将其呈现到我的 html 页面:
return render_template("solved.html", ambiguousCase=session['ambTrue'], angles=session['angles'], sides=session['sides'])
我尝试以多种方式访问列表的特定元素:
<label>Angle of A = {{ angles.0 }}</label>
<label>Angle of B = {{ angles.0 }}</label>
<label>Angle of C = {{ angles.2 }}</label>
<label>Side Length of a = {{ sides.0 }}</label>
<label>Side Length of b = {{ sides.1 }}</label>
<label>Side Length of c = {{ sides.2 }}</label>
和
<label>Angle of A = {{ angles[0] }}</label>
<label>Angle of B = {{ angles[1] }}</label>
<label>Angle of C = {{ angles[2] }}</label>
<label>Side Length of a = {{ sides[0] }}</label>
<label>Side Length of b = {{ sides[1] }}</label>
<label>Side Length of c = {{ sides[2] }}</label>
这两种方法都给我这个错误:
jinja2.exceptions.UndefinedError
jinja2.exceptions.UndefinedError: 'angles' is undefined
我知道在 jinja 中你可以使用 for 循环来访问列表的元素:
{% for angle in angles %}
<h1>{{ angle }}</h1>
{% endfor %}
但我认为这不适用于我的代码。 我犯了什么错误?
解决了
我没有使用重定向函数,而是使用了 render_template 函数。 所以我定义所有变量的路径从未被调用
我的错误
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.