flask - url with searched word

flask, python

Solution

You're now using POST request. Use GET request, so browser will put your form values to URL.

in HTML form set method="GET":

<form name="filters" action="{{ url_for('filter') }}" method="GET" id="filters">

You'll get URL in the following form:

http://host/filter?search_string=test&chosen=<id>&<some other trash>

In Flask use request.args instead of request.form:

if request.method == 'GET':
    if request.args.get('search_string'):
        ...

Problem

I want to ask how to make my urls to include the worh that I searched. Something like this: ``` http://host/filter?test ``` My code: ``` @app.route('/filter', methods=['POST', 'GET']) def filter(): if request.method == 'POST': if str(request.form['search_string']) <> '': api.queryMessage(request.form['search_string']) return render_template('main.html', search_string=search_string) ``` And my template, main.html: ``` <form name="filters" action="{{ url_for('filter') }}" method=post id="filters"> <div style="position: absolute; top:100px; left:300px"> <p>Search string: <input type=text size=80 title="Match all of the words" name=search_string value="{{search_string}}"></p> <input type=submit value=Filter/Search onclick=loopSelected();> <input type="hidden" name="chosen" id="chosen" value="{{chosen}}" /> </div> </form> ```

Original source