Flask app search bar

给你一囗甜甜゛ 提交于 2019-12-03 00:52:14

Because when you load page manually you using GET method, but only POST is allowed for search controller. You need to change

@app.route('/search', methods=['POST'])

to

@app.route('/search', methods=['GET', 'POST'])

UPDATE

So basically it's better to change your search controller. Because it's not using search.html and works wrong.

@app.route('/search', methods=['GET', 'POST'])
@login_required
def search():
    form = SearchForm()
    if request.method == 'POST' and form.validate_on_submit():
        return redirect((url_for('search_results', query=form.search.data)))  # or what you want
    return render_template('search.html', form=form)

Also make indentation 4 spaces, as it said in PEP-8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!