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)
精彩评论