折腾:
[已解决]Flask中对于SQLAlachemy中检索特定时间内的条目
期间,用代码:
todayEventList = Event.query.filter_by(and_(user_openid=curUser.openid, start_date >= todayStart, start_date <= todayEnd)).all() |
结果出错:
File “/root/html/SIPEvents/sipevents/views.py”, line 387 todayEventList = Event.query.filter_by(and_(user_openid=curUser.openid, start_date >= todayStart, start_date <= todayEnd)).all() SyntaxError: non-keyword arg after keyword arg |
去加上:
from sqlalchemy import or_, and_ |
结果,错误依旧。
搜:
sqlalchemy SyntaxError: non-keyword arg after keyword arg
python – sqlalchemy SyntaxError: non-keyword arg after keyword arg – Stack Overflow
Python: SyntaxError: non-keyword after keyword arg – Stack Overflow
-》看起来是:
todayEventList = Event.query.filter_by(and_(user_openid=curUser.openid, start_date >= todayStart, start_date <= todayEnd)).all() |
中的:
and_
就不支持?
“You cannot put a non-keyword argument after a keyword argument.”
python – [sqlalchemy]SyntaxError: non-keyword arg after keyword arg – Stack Overflow
把=换成==:
todayEventList = Event.query.filter_by( and_(user_openid == curUser.openid, start_date >= todayStart, start_date <= todayEnd)).all() |
结果:
就可以正常运行了。
至少没有报错。
[总结]
此处Python代码中,用:
todayEventList = Event.query.filter_by(and_(user_openid=curUser.openid, start_date >= todayStart, start_date <= todayEnd)).all() |
出错:
SyntaxError: non-keyword arg after keyword arg
的解决办法是:
把”=“,换成”==“,即可:
todayEventList = Event.query.filter_by( and_(user_openid == curUser.openid, start_date >= todayStart, start_date <= todayEnd)).all() |
转载请注明:在路上 » [已解决]SQLAlchemy查询出错:SyntaxError: non-keyword arg after keyword arg