开发者

web2py: how to download image with SQLTABLE

开发者 https://www.devze.com 2023-04-09 23:13 出处:网络
I\'d like to know if it\'s possible use SQLTABLE to build开发者_Go百科 up a list of images. Images are in a database table, but I don\'t want just a link to download.You can do it in a number of ways:

I'd like to know if it's possible use SQLTABLE to build开发者_Go百科 up a list of images. Images are in a database table, but I don't want just a link to download.


You can do it in a number of ways:

First:

db.table.field.represent = lambda r, v: IMG(_src=URL('default',
                                                     'download',
                                                      args=v.field))

# where field is the field where your picture lives.

Second is using web2py virtual fields:

class MyVirtual(object):
    def photo(self):
        return IMG(_src=URL('default', 'download', args=self.table.field))

db.table.virtualfields.append(MyVirtual())

table = SQLTABLE(db(db.table).select())

Third is using extracolumns:

myextracolumns = [{'label': 'My Photo',
                   'content': lambda row, rc: IMG(_src=URL('default',
                                                           'download',
                                                            args=row.field))}]

table = SQLTABLE(rows, extracolumns=myextracolumns)
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号