<p>我不熟悉flask和python,当我尝试用“LIKE%s”从我的数据库检索flask应用程序时,我得到AttributeError(“'list'object has no attribute'keys'”),但如果我使用占位符“title=:result”,我将只检索一行,但不能使用LIKE子句,我只能检索数据库中的确切数据不知道如何检索解决我手头的问题,任何帮助都将不胜感激。在</p>
<p>在应用程序.py在</p>
<pre><code>@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)
</code></pre>
<p>如果我能得到任何帮助,我将不胜感激。提前谢谢!在</p>
<p>回溯</p>
^{pr2}$