class fruit(flaskform):
fruit1 = "apple"
fruit2 = "orange"
fruit3 = "grapes"
我正在尝试访问html页面中for循环中的变量。
{% for index in range(3) %}
{{"fruit" + index}}
{%endfor%}
这个是可能的吗?如果我有100个结果,我希望避免编写100行代码来访问变量。我是第一次接触flask和html。我的问题可能不清楚,如果需要更多信息,请随时询问我。
发布于 2018-08-08 04:32:05
您可以将您的水果存储在如下列表中:
fruits = ['apple', 'orange', 'grapes']
然后,可以在Jinja2中使用for循环遍历列表并显示每个单独的项目。
{% for fruit in fruits %}
{{ fruit }}
{% endfor %}
https://stackoverflow.com/questions/51733288
复制相似问题