我正在尝试将搜索栏中的用户输入返回数据库,并根据用户输入生成表。但是,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不允许我提交
答案 0 :(得分:0)
尝试更改
# encoding=utf8
import sys
reload(sys)
sys.setdefaultencoding('utf8')
import re
import sys
import os
import nltk
import pandas as pd
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.feature_extraction.text import CountVectorizer
#import sys
#reload(sys)
#sys.setdefaultencoding("ISO-8859-1")
#a.encode('utf-8').strip()
os.chdir("/Users/lucy/Desktop/down1")
file=[]
for files in os.listdir("/Users/lucy/Desktop/down1"):
with open(files) as f:
#files.encode('utf-8').strip()
lineList = f.readlines()
lines=b" ".join(lineList)
lines=[lines]
vectorizer = CountVectorizer(stop_words='english')
#[texts]=yes
word_count_vector=vectorizer.fit_transform(lines)
#with open(os.path.join(root,files),"r") as auto:
file.append(word_count_vector)
#print(file)
print(vectorizer.vocabulary_)
到
<form role="form" id="form-buscar">