0

我使用了以下代码:

import MySQLdb
import base64
from PIL import Image
import cStringIO

db = MySQLdb.connect(host="localhost",
                     user="root",
                     passwd="root",
                     db="test")
# select statement with explicit select list and where clause instead of select * ...
sql1='select img from images where id=1'  
cursor = db.cursor()
cursor.execute(sql1)
data2=cursor.fetchall()
cursor.close()
db.close()

file_like=cStringIO.StringIO(base64.b64decode(data2[0][0]))

img1=Image.open(file_like,mode='r').convert('RGB')
img1.show()

一切正常。如何使用 html 文件显示此图像

你能把代码发给我吗,如果有的话

4

1 回答 1

0

您需要使用 Flask 或 Django 等 Python Web 框架来为 Web 创建视图。

然后,您可以将此模块导入 python web 框架,flask 或 Django 以将图像提供给网页。

于 2018-01-17T11:38:00.217 回答