我试图将用户从搜索栏中输入的内容返回到数据库中,并根据用户输入生成一个表。但是,flask打印error1。你知道吗
@app.route('/', methods=['GET', 'POST'])
def homepage1():
try:
if request.method == "POST":
x = request.form
print(x)
name =x['search']
a = name.split(" ",1)
firstname, lastname = (a[0], a[1])
print(firstname)
print(lastname)
c,conn = connection()
qry = "SELECT FirstName, LastName, Location FROM posts WHERE FirstName LIKE (%s) AND LastName like (%s)"
c.execute(qry, ((thwart(firstname)), (thwart(lastname)),))
conn.commit()
data = c.fetchall()
conn.close()
return render_template("index.html", data=data)
else: print('error1')
return render_template("review.html")
except Exception as e:
return(str(e))
<div class="container" style="margin-top: 10%; margin-left: 25%">
<div class="col-md-6 col-md-offset-3">
<div class="row">
<div id="logo" class="text-center">
<form role="form" id="form-buscar">
<div class="form-group">
<div class="input-group">
<input id="1" class="form-control" type="text" name="search" placeholder="Enter First Name, Last Name..." required/>
<span class="input-group-btn">
<button type="button" class="btn btn-success" type="submit" method = "POST" id="search" onclick="fetchlist()" >
<i class="glyphicon glyphicon-search" aria-hidden="true"></i> Search
function fetchlist() {
if (document.getElementById('search').onclick) {
document.getElementById('list').style.display = 'block';
}
else document.getElementById('list').style.display = 'none';
}
我的标签已关闭,但Stackoverflow不允许我提交
尝试改变
至
相关问题 更多 >
编程相关推荐