开发者

web2py: how to download image with SQLTABLE

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜