我一直在尝试构建一个搜索表单,从mysqldb本地创建的数据库中读取isbn、作者、年份和标题。
即使我考虑了几个网站,尝试教程,使之成为现实,我找不到一个最佳的方式来做到这一点。现在我所做的就是这样。
Python代码@app.route('/search_results/', methods = ['GET','POST'])
@is_logged_in
def search_results(query):
cur=mysql.connection.cursor()
likeString = "'%%" + query + "%%'"
result = cur.execute("SELECT * FROM books WHERE %s LIKE %s;", (query, likeString))
if result > 0:
data = cur.fetchall()
return render_template('search_results.html' , data = search)
else:
error = 'Nothing found'
return render_template('dashboard.html' , error = error)
return render_template('dashboard.html')
@app.route('/dashboard')
@is_logged_in
def dashboard():
search = SearchForm(request.form)
if request.method == 'POST':
select = form.select.data
search = form.search.data
query = select + search
return redirect((url_for('search_results', query = query)))
return render_template('dashboard.html', form = search)
我的html代码以下内容:-在
^{pr2}$
我创建了一个单独的搜索_结果.html同样,除了显示如下搜索的标题H1外,它不包含任何内容