<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
{% extends "base.html" %}
{% block title %}详情{% endblock %}
{% block page_content %}
<table class="table table-bordered">
<tr>
<th>编号</th>
<th>标题</th>
<th>内容</th>
</tr>
{% for i in u %}
<tr>
<td>{{ i[0] }}</td>
<td>{{ i[1] }}</td>
<td>{{ i[2] }}</td>
</tr>
{% endfor %}
</table>
{% endblock %}
<form action=" search" method="post">
<a>keyword:</a>:<input type="text" name="keyword">
<button type="submit">搜索</button>
</form>
def result(keyword):
mydb = mysql.connector.connect(
host="localhost",
user="root",
passwd="1234",
database="oac"
)
mycursor = mydb.cursor()
sql1 = ("SELECT m_id,m_title,m_content FROM message where concat(m_content,m_title) like '%%%s%%' " %keyword)
mycursor.execute(sql1)
u = mycursor.fetchall()
mydb.commit()
return u
@app.route('/search',methods=["post","get"])
def search():
keyword=request.form.get('keyword')
res=result(keyword)
print(res)
return render_template('result.html',res=res)
一个基于flask的搜索框
后端输出的数据都是对的,但是HTML页面上没有显示