【问题标题】:Retrieving images from mysql and displays on webpage从 mysql 中检索图像并显示在网页上
【发布时间】:2018-01-17 20:43:32
【问题描述】:

我使用了以下代码:

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 文件显示此图像

如果有的话,可以把代码发给我吗

【问题讨论】:

    标签: python image display webpage-rendering


    【解决方案1】:

    您需要使用 Flask 或 Django 等 python 网络框架来为网络创建视图。

    然后你可以将你的这个模块导入到 python 网络框架中,无论是烧瓶还是 Django,以将图像提供给网页。

    【讨论】:

      猜你喜欢
      • 2015-10-08
      • 2013-12-11
      • 1970-01-01
      • 2021-12-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多