我是flask和python的新手当我尝试使用“LIKE %s”从我的flask应用程序中的数据库中检索时,我得到AttributeError(“‘list’对象没有属性‘keys’”,)但如果我使用占位符“ title =:result" 我将只检索一行,但我不能使用 LIKE 子句我只能检索我在数据库中的确切数据不知道如何解决我手头的问题,任何帮助都会受到高度赞赏。
应用程序.py
@app.route("/search",methods=['GET', 'POST'])
def search():
if request.method=='GET':
return render_template("search.html")
#search=request.form.get['search']
else:
try:
res =request.form.get('search')
likeString = "'%%"+res+"%%'"
if likeString!="":
#return (res)
results=db.execute('''SELECT title FROM books WHERE title LIKE %s;''', likeString).fetchall()
#results=db.execute("SELECT title FROM books WHERE title =:result",
#{"result": res}).fetchall()
if results is None:
return render_template("error.html", message="No such book")
else:
return render_template("search.html",results=results)
else:
return ("you didn't enter a search value")
except Exception as e:
raise ValueError ("could not retrieve from database",e)
如果我能得到任何帮助,我将不胜感激。提前致谢!
单机有带宽瓶颈,那么负载均衡设备就不存在带宽瓶颈了吗?
问题有的烧脑, 无法排查错误,请大神排查问题。
没有基础的初中生好学不好,大家的建议呢?有没有大师带带?
代码打出瓶盖问题
相关分类