Flo*_*rin 11 database upload image web2py
是否有web2py方式显示数据库表中的图像?
例:
该模型:
db.define_table=('images',Field('picture', 'upload' ))
Run Code Online (Sandbox Code Playgroud)
控制器:
def somefunction(): to get the image.
Run Code Online (Sandbox Code Playgroud)
我究竟应该如何"读取"数据库中的图片?
风景:
<img src="{{somefunction}}" />
Run Code Online (Sandbox Code Playgroud)
Ant*_*ony 16
因此,您的模型不会将图像存储在数据库中 - 而是将图像存储在文件系统中,其新文件名存储在数据库中(在"图片"字段中).如果要将图像本身存储在数据库中,请使用以下命令:
db.define_table('images',
Field('picture', 'upload', uploadfield='picture_file')
Field('picture_file', 'blob'))
Run Code Online (Sandbox Code Playgroud)
无论是将图像存储在文件系统还是数据库中,都可以使用相同的方法来检索它们.'welcome'脚手架应用程序download()在default.py控制器中包含以下操作:
def download():
return response.download(request, db)
Run Code Online (Sandbox Code Playgroud)
要检索图像,只需执行以下操作:
<img src="{{=URL('default', 'download', args=picture_name)}}" />
Run Code Online (Sandbox Code Playgroud)
哪个picture_name值存储在您要检索的特定图像picture的' images'表的' '字段中.
如果您需要进一步的帮助,请尝试在邮件列表中询问.