How can I put an image from DB table in Web2py?
I'm try开发者_运维知识库ing to put an image in view section I have defined a table but it seems{{for table in tables:}}
doesn't work. My code is:
default.py (Controller)
def index():
return dict(message=T('Hello World'))
def Tables():
return dict(tables=db().select(db.table.ALL))
def download():
return response.download(request, db)
db.py (model)
db.define_table('table',
Field('image', type='upload')
This is it and I tried to do {{for table in tables:}}
before putting the image, but it says, the tables is not defined.
I used {{pass}}
after for
. Can you guys help me a bit?
Cheers
Are you trying to edit which view?
from your code it will work well:
in model
db.define_table('mytable',
Field('image', type='upload'))
# I do not recommend calling a table 'table' it is can be a reserved keyword
in dontrollers/default.py
def tables():
return dict(tables=db().select(db.mytable.ALL))
in views/default/tables.html
{{for table in tables:}}
<img src="{{=URL('default', 'download', args=table.image)}}" /> <br />
{{pass}}
精彩评论