我有这个功能(SQLAlchemy):
# table: Table to search (should be the class name)
# column: filter to use
# search: search term
#
# Returns a list [object] with the found entries in the database
# Uses the SQL LIKE statement
def search(table, column, search):
results = dbsession.query(table).filter(column.like('%' + search + '%')).all()
return results
所以这个搜索函数在类'table'中搜索,使用过滤器'column'并搜索'search'。我现在遇到的问题是,如果我为“列”输入一个值(实际上不是字符串,而是一段代码),我总是会收到一个错误,即名称不存在:
users = search(User, fname, 'Jo')
NameError: name 'fname' is not defined
有人知道如何正确编码吗?