【发布时间】:2020-09-14 17:36:00
【问题描述】:
我正在尝试从 s3 存储桶中获取图像,并使用烧瓶(以及使用 boto3 访问存储桶)将它们显示在网页上。
我目前有一个桶中所有图片的列表,但无法获取 html 来显示它们(给我 404 错误)。
如何在不下载文件的情况下执行此操作? 这是我目前所拥有的:
def list_files(bucket):
contents = []
for image in bucket.objects.all():
contents.append(image.key)
return contents
def files():
list_of_files = list_files(bucket)
return render_template('index.html', my_bucket=bucket, list_of_files=list_of_files)
这是 html sn-p:
<table class="table table-striped">
<br>
<br>
<tr>
<th>My Photos</th>
{% for f in list_of_files %}
<td> <img src="{{ f }}"></td>
{% endfor %}
非常感谢!
【问题讨论】: