我在控制器中有这样的查询(许多列被注释掉)
rows=db( (c.email_sent == 0 ) & (c.status=='pending') ).select(db.f.first_name #.with_alias('requester_name') ,
# db.t.first_name.with_alias('receiver_name'),db.t.email.with_alias('sendto_email'),
# db.c.from_id.with_alias('sender_id'),db.c.to_id.with_alias('receiver_id'),
# db.c.id.with_alias('connection_id')
,join =
[db.f.on (db.f.id==c.from_id),
db.t.on(db.t.id==c.to_id)]
)
视图有
{{extend 'layout.html'}}
<table class="table">
{{for row in rows:}}
<tr>
<td>={{row.first_name}</td>
</tr>
</table>
它工作正常。但是如果我从控制器中删除注释掉的别名,我就无法使视图工作。我收到一个错误 - “(Rows对象出错了)”
函数参数列表是(self =,sqlrows =,linkto = None,upload = None,orderby = None,headers = {},truncate = 16,columns = ['f.first_name AS requester_name','t.first_name AS receiver_name ','t.email AS sendto_email','c.from_id AS sender_id','c.to_id AS receiver_id','c.id AS connection_id'],th_link ='',extracolumns = None,selectid = None,renderstyle = False,cid = None,colgroup = False,** attributes = {})
显然,列名未正确传递。该怎么做?
答案 0 :(得分:0)
如果您为某个字段添加别名,则在访问该行中的该字段时使用别名:
{{=row.requester_name}}
另一个选择是跳过使用别名 - 它们似乎没有必要。在这种情况下,由于查询涉及联接,您可以通过row.tablename.fieldname
访问单个字段值。