search

Home  >  Q&A  >  body text

python - SyntaxError: keyword can't be an expression

  1 # -*- coding:utf-8 -*-
  2 from Shares.sqlconn import *
  3 from sqlalchemy.orm import sessionmaker
  4 
  5 def CheckLogin(name,passwd):
  6     session = Session().get_session()
  7     flag = session.query(User).filter(User.name=name,User.passwd=passwd).one_or_none()                                                                                                       
  8     session.close()
  9     if flag:
 10         return True
 11     return False

I use sqlalchemy in django but filtering will report an error

  File "/root/Shares/user/check_login.py", line 7
    flag = session.query(User).filter(User.name=name,User.passwd=passwd).one_or_none()
SyntaxError: keyword can't be an expression

May I ask the masters how to solve it

给我你的怀抱给我你的怀抱2772 days ago3556

reply all(2)I'll reply

  • 漂亮男人

    漂亮男人2017-05-18 10:58:29

    The correct way to write it should be

    flag = session.query(User).filter(User.name==name,User.passwd==passwd).one_or_none()

    That’s it

    reply
    0
  • 黄舟

    黄舟2017-05-18 10:58:29

    User.nameUser.passwd不是正确的参数名.可能是User_name,User_passwd. Please check the documentation of the relevant libraries for details

    reply
    0
  • Cancelreply