Skip to content Skip to sidebar Skip to footer

How Can I Put An Image From Db Table In Web2py?

I'm trying 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 dic

Solution 1:

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:}}
    <imgsrc="{{=URL('default', 'download', args=table.image)}}" /><br />
{{pass}}

Post a Comment for "How Can I Put An Image From Db Table In Web2py?"