我正在尝试从 web2py 中的视图中查询数据库表,因为我需要从另一个表中为当前表中的每一行获取一个字段,所以我编写了如下代码:
{{for recipe in rows:}}
<div class="well">
<table>
<tr>
<td>
<div style="text-align:center">
<img width="200px"
src="{{=URL('download', args=db(db.uploads.recipe_id==recipe.id).select().first().up_file)}}" />
</div>
</td>
<td><button>
-
</button></td><td><span class='votes'>{{=recipe.votes}}</span></td><td><button>
+
</button><td><strong>{{=A("comments",_href=URL('view_posts',args=recipe.id))}},{{=recipe.name}}</strong></td></td></tr>
</table>
</div>
{{pass}}
但我怀疑我们是否可以从视图中查询数据库?如果不是,我如何从控制器查询相同的内容并将其返回给视图?这可能是一个愚蠢的疑问,但抱歉我是 web2py 的新手