我一直在试图弄清楚如何将 request.args 传递给 sqlalchemy 过滤器。
我认为这应该工作:
model.query.filter(**request.args).all()
但它抛出了错误:
TypeError: <lambda>() got an unexpected keyword argument 'userid'
当 userid 或任何其他 get arg 存在时。
根据这篇文章 - https://stackoverflow.com/questions/19506105/flask-sqlalchemy-query-with-keyword-as-variable - 您可以将 dict 传递给过滤器函数。
任何想法我做错了什么?
非常感谢 :)
更新:非常感谢下面的海报,但是现在它抛出了以下错误:
ProgrammingError: (ProgrammingError) (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') ORDER BY tblclients.clientname' at line 3") 'SELECT favourites.id AS favourites_id, favourites.userid AS favourites_userid, favourites.clientid AS favourites_clientid, favourites.last_visit AS favourites_last_visit \nFROM favourites INNER JOIN tblclients ON tblclients.clientid = favourites.clientid \nWHERE favourites.userid = %s ORDER BY tblclients.clientname' ([u'41'],)
有任何想法吗?