最新消息:20210917 已从crifan.com换到crifan.org

[已解决]SQLAlchemy查询出错:SyntaxError: non-keyword arg after keyword arg

Flask crifan 3341浏览 0评论

折腾:

[已解决]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_

就不支持?

“SyntaxError: non-keyword arg after keyword arg” Error in Python when using requests.post() – Stack Overflow

“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

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
92 queries in 0.199 seconds, using 23.55MB memory