Web2py:我应该如何显示存储在数据库中的上传图像?

编程入门 行业动态 更新时间:2024-10-25 14:26:44
本文介绍了Web2py:我应该如何显示存储在数据库中的上传图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

是否有从数据库表中显示图片的web2py方法?

示例:

db.define_table =('images',Field('picture','upload'))

控制器:

def somefunction():获取图像。

我应该如何从数据库读取图片?

视图:

< img src ={{somefunction}}/>

解决方案

相反,它将图像存储在文件系统上,其新文件名存储在数据库中(在图片字段中)。如果要将图像本身存储在数据库中,请使用以下命令:

db.define_table('images', Field('picture','upload',uploadfield ='picture_file')字段('picture_file','blob'))

无论是将映像存储在文件系统还是数据库中,都可以使用相同的方法来检索它们。 welcome脚手架应用程序在 default.py 控制器中包括以下 download()操作:

def download(): return response.download(request,db) / pre>

要检索图片,只需执行以下操作:

< img src ={{= URL('default','download',args = picture_name)}}/>

其中 picture_name 您要检索的特定图片的图片表格中的图片字段。

有关详情,请参见此处和此处。

如果您需要进一步的帮助,请尝试邮寄列表。

Is there a web2py way of displaying images from a database table?

Example:

The model:

db.define_table=('images',Field('picture', 'upload' ))

The controller:

def somefunction(): to get the image.

How exactly should I "read" a picture from the database?

The view:

<img src="{{somefunction}}" />

解决方案

As is, your model will not store the image in the database -- instead, it will store the image on the filesystem, with its new filename stored in the database (in the 'picture' field). If you want to store the image itself in the database, use the following:

db.define_table('images', Field('picture', 'upload', uploadfield='picture_file') Field('picture_file', 'blob'))

Whether you store the images on the filesystem or in the database, you can use the same method to retrieve them. The 'welcome' scaffolding application includes the following download() action in the default.py controller:

def download(): return response.download(request, db)

To retrieve an image, just do something like:

<img src="{{=URL('default', 'download', args=picture_name)}}" />

where picture_name is the value stored in the 'picture' field of the 'images' table for the particular image you want to retrieve.

For more details, see here and here.

If you need further help, try asking on the mailing list.

更多推荐

Web2py:我应该如何显示存储在数据库中的上传图像?

本文发布于:2023-10-23 14:11:49,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据库中   图像   上传   Web2py

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!