且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Sqlalchemy.类型错误:filter_by() 只需要 1 个参数(给定 2 个)

更新时间:2023-12-04 11:00:58

没有看到代码,显然你在调用 filter_by 错误.filter_by 只接受隐含的 self('exactly 1 argument' 表示恰好 1 个位置参数)和可选的关键字参数.您正在提供 filter_by 另一个位置参数,可能是字典.

Without seeing code, obviously you are calling filter_by wrong. filter_by takes only the implicit self (the 'exactly 1 argument' meaning exactly 1 positional argument) and optional keyword arguments. You are providing filter_by another positional argument, possibly a dictionary.

语法是:

query.filter_by(column1=value, column2=value)

而对于 filter:

query.filter(Model.column1 == value, Model.column2 == value)