【发布时间】:2020-10-08 06:18:57
【问题描述】:
我正在寻找一个简单的社交网络网络应用程序。在提要页面中,我应该打印所有帖子,包括上传它的用户的姓名以及每个帖子的反馈。
我在显示 Jinja 嵌套循环时遇到了问题,因为我不了解有关 html 的良好背景。
这是我的 html 文件,其中我有 3 个用于用户名、反馈和帖子的嵌套循环。它只打印用户和反馈的第一个结果而忽略其余部分的问题。我需要显示所有帖子的结果,例如“用户反馈帖子”。
{% for item1 in user %}
{% for item2 in feed %}
{% for item3 in image %}
{{ item1 }} {% if not loop.last %} {% endif %}<br>
{{ item2 }} {% if not loop.last %} {% endif %}<br>
<img src="/static/images/{{ item3 }}" width="180" height="180"><br> {% if not loop.last %} {% endif %}<br><br>
{% endfor %}
{% endfor %}
{% endfor %}
file.py 我返回函数的地方...
return render_template("home.html", feed=post_feed(), image=post_image(), user=post_user())
【问题讨论】:
标签: python html flask jinja2 nested-loops