我是flask和python的新手當(dāng)我嘗試使用“LIKE %s”從我的flask應(yīng)用程序中的數(shù)據(jù)庫(kù)中檢索時(shí),我得到AttributeError(“‘list’對(duì)象沒有屬性‘keys’”,)但如果我使用占位符“ title =:result" 我將只檢索一行,但我不能使用 LIKE 子句我只能檢索我在數(shù)據(jù)庫(kù)中的確切數(shù)據(jù)不知道如何解決我手頭的問題,任何幫助都會(huì)受到高度贊賞。應(yīng)用程序.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)如果我能得到任何幫助,我將不勝感激。提前致謝!
添加回答
舉報(bào)
0/150
提交
取消