使用Python在HTML页面中显示图像时出现问题
我正在尝试使用 Python 和 Flask 在 HTML 表中显示图像,但它仍然显示“无法加载图像”图标,当我尝试在另一个选项卡中打开它时,我得到以下信息:
“数据” 链接被阻止
网页位于数据:image/png;base64,b'\xfahg\xffZX\xff[Y\xff[Y\xff[Y\xff[Y\xff[Y\xff[Y\xff[Y\xff[Y\xff[Y] \xff[Y\xff[Y\xff[Y\xff[ Y\xff[Y\xff[Y\xff[Y\xff[Y\xff[Y\xff[Y\xff[Y\xff[Y\xff[Y\xff[Y\xff[Y\xff[Y\ xff[Y\xff\\V\xe5YeoQ\x9a^P\xa3`P\...
可能会暂时关闭,或者可能已永久移动到新网址。
我的 HTML 模板中有以下内容:
<tr>
<td>{{ puzzle["Name"] }}</td>
<td>{{ puzzle["Type"] }}</td>
<td>{{ puzzle["AssetsSize"] }}</td>
<td>
<img src="data:image/png;base64,{{ convert_image(puzzle) }}">
</td>
</tr>
convert_image()
函数返回以下内容:
def Convert_image(data):
如果数据中有“缩略图”:
返回数据['Thumbnail'].encode("latin1")
return "Thumbnail Unavailable"
关于我做错了什么有什么提示或想法吗?
在从函数返回之前,我已经尝试过使用 base64 进行编码,但也不起作用。
I am trying to display an image in an HTML table using Python and Flask, but still, it shows that "the image couldn't be loaded" icon, and when I try to open it in another tab I get the following:
“data” links are blocked
The webpage at data:image/png;base64,b'\xfahg\xffZX\xff[Y\xff[Y\xff[Y\xff[Y\xff[Y\xff[Y\xff[Y\xff[Y\xff[Y\xff[Y\xff[Y\xff[Y\xff[Y\xff[Y\xff[Y\xff[Y\xff[Y\xff[Y\xff[Y\xff[Y\xff[Y\xff[Y\xff[Y\xff[Y\xff[Y\xff[Y\xff\\V\xe5YeoQ\x9a^P\xa3`P\...
might be temporarily down or it may have moved permanently to a new web address.
I have the following in my HTML template:
<tr>
<td>{{ puzzle["Name"] }}</td>
<td>{{ puzzle["Type"] }}</td>
<td>{{ puzzle["AssetsSize"] }}</td>
<td>
<img src="data:image/png;base64,{{ convert_image(puzzle) }}">
</td>
</tr>
And the convert_image()
function returns the following:
def convert_image(data):
if 'Thumbnail' in data:
return data['Thumbnail'].encode("latin1")
return "Thumbnail Unavailable"
Any tips or thoughts on what I am doing wrong?
I have already tried encoding with base64 before returning from the function, but did not work either.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
base64
编码的。数据
不是PNG文件。PNG 文件以 8 字节签名 开头,应如下所示:
<强>参考文献:
base64
encoded.data
is not a PNG file.A PNG file starts with an 8-byte signature that should look something like this:
References: