显示多个图像html

时间:2020-02-23 15:09:07

标签: html image

我正在用Flask编写一个网站,该网站旨在呈现通过JSON从后端接收到的图片(其中的网址)。我想用引导卡组件或类似的东西(例如轮播)来渲染每张图片。

图片的数量有时会有所不同,因此我无法创建具有许多div块的精确数量的卡片-应该对该参数进行参数设置。

def render():
    # some code here to receive and parse json
    # images - is an array of url's
    n = len(images)
    return render_template('index.html', n=n, images=images)

然后在.html文件中我要绘制n个块,每个块看起来像

    <div class="card" style="width: 18rem;">
      <img src="{{ images[0] | safe }}" class="card-img-top" alt="...">
      <div class="card-body">
        <h5 class="card-title">Name</h5>
        <p class="card-text">Description</p>
      </div>
    </div>

怎么可能?

1 个答案:

答案 0 :(得分:0)

似乎只有一个简单的for循环有效

    {% for image in images %}
        <div class="card-body" style="width: 18rem;">
          <img src="{{ image | safe }}" class="card-img-top" alt="...">
        </div>
    {% endfor %}
相关问题