为什么我的搜索关键字出现“ 400错误的请求:KeyError:'search'”错误?

时间:2018-12-10 20:15:57

标签: python flask

我正在尝试使搜索栏工作。它给我一个错误,说我在主页面上使用Python和flask库编码的400 Bad Request:KeyError:'search'。请帮我修复它。

@app.route('/', methods=['POST', 'GET'])
def index():
if (request.args['search']):
    tag = request.args.get("tagname")
    query = "select * from quote,tags,quote_tags where quote.qid = 
 quote_tags.qid and tags.tagid = quote_tags.tagid and tagname=" + str(tag)
    cur = connection.execute(query)
    rv = cur.fetchall()
    cur.close()
    return render_template('index.html', tag=rv)
else:
    return render_template('index.html')

这是我的搜索栏HTML代码,图像是输入按钮:

<input type="text" placeholder="Search.." name="search" class="searchbar">
    <a href="/searchresults?tagname={{tag[0]}}"> <img src="../static/SearchIcon.png" Class="searchbar icon"></a>

0 个答案:

没有答案