Skip to main content
 首页 » 编程设计

python之从 BaseQuery 对象获取结果

2025年05月04日14lexus

我正在使用 SQLalchemy 并将数据输入数据库:

class Directions(db.Model): 
    id = db.Column(db.Integer, primary_key=True) 
    key = db.Column(db.String(16), index=True, unique=False) 

现在,我正在尝试搜索给定的键:

Directions.query.filter(Directions.key=={some string}) 

但是我得到:

<flask_sqlalchemy.BaseQuery object at 0x103df57b8> 

我如何发现实际结果?

请您参考如下方法:

尝试使用这个:

direction = Directions.query.filter_by(key == <some string>).first() 
print(direction)