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
漂亮男人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
黄舟2017-05-18 10:58:29
User.name
和User.passwd
不是正确的参数名.可能是User_name
,User_passwd
. Please check the documentation of the relevant libraries for details