如何将 DB 表中的图像放入 Web2py? [英] How can I put an image from DB table in Web2py?

查看:20
本文介绍了如何将 DB 表中的图像放入 Web2py?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将图像放入视图部分,我定义了一个表,但似乎{{for table in tables:}} 不起作用.我的代码是:

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(控制器)

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 未定义.我在 for 之后使用了 {{pass}}.你们能帮我一点吗?

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?

干杯

推荐答案

您是否正在尝试编辑哪个视图?

Are you trying to edit which view?

从您的代码来看,它会运行良好:

from your code it will work well:

在模型中

db.define_table('mytable',
          Field('image', type='upload'))

# I do not recommend calling a table 'table' it is can be a reserved keyword

在 dontrollers/default.py

in dontrollers/default.py

def tables(): 
   return dict(tables=db().select(db.mytable.ALL))

在视图/默认/tables.html

in views/default/tables.html

{{for table in tables:}}
    <img src="{{=URL('default', 'download', args=table.image)}}" /> <br />
{{pass}}

这篇关于如何将 DB 表中的图像放入 Web2py?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆