如何在sqlalchemy filter()函数中使用python变量?
dog_name=userinput()
#userinput()是已定义的函数chosen_dog=session.query(Dog).filter(Dog.name==dog_name)
答案 0 :(得分:1)
尝试:
chosen_dog=session.query(Dog).filter_by(name = dog_name).one()
答案 1 :(得分:0)
只有filter(Dog.name=dog_name)