TypeError: 'BaseQuery' object is not callable Flask [duplicate]

六月ゝ 毕业季﹏ 提交于 2019-12-22 04:33:33

问题


I am getting this error:

TypeError: 'BaseQuery' object is not callable

Here is my code:

companies = Company.query.all()
return Company.query(func.count(Company.id))

I need to find out number of rows in Company model. Please help!


回答1:


Company.query isnt callable there. If you've already selected all your companies with companies = Company.query.all(), why not simply use len(companies)?

If you dont want/need to retrieve the data, you can get just the count with Company.query.count()



来源:https://stackoverflow.com/questions/18058438/typeerror-basequery-object-is-not-callable-flask

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!