我正在尝试将图像放入视图部分我已经定义了一个表,但似乎{{for table in tables:}}
不起作用。我的代码是:
default.py (控制器)
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 (型号)
db.define_table('table',
Field('image', type='upload')
就是这样,我在放置图片之前尝试{{for table in tables:}}
,但它说tables is not defined.
我在{{pass}}
之后使用了for
。你能帮帮我一点吗?
干杯
答案 0 :(得分:0)
您是否正在尝试修改哪个视图?
从您的代码它将运作良好:
在模型中
db.define_table('mytable',
Field('image', type='upload'))
# I do not recommend calling a table 'table' it is can be a reserved keyword
def tables():
return dict(tables=db().select(db.mytable.ALL))
在views / default / tables.html
中{{for table in tables:}}
<img src="{{=URL('default', 'download', args=table.image)}}" /> <br />
{{pass}}