I have 2 html files in my templates folder: home.html, and search.html. I have a flask backend, and basically every time I run my application it loads my home.html file first. I have a search bar on my home page, and the idea is whenever someone types something into the search bar and presses enter, my search.html page is loaded and a GET request is made.
The search bar on my home page is form, below is the code.
<form class="form-inline" role="search" method="get">
<input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search" name="q">
<button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
</form>
I expected my url to change to the typical GET request format:"http://.../search?q?=whateverTextWasEnteredIntoTheForm"
However whenever I type into my form on my home page and hit the search button, my application navigates to my search.html page as it should but it seems like my query is completely lost. The url I'm left with is just "http://.../search?" Why?
I've also included the two flask methods I have thus far.
This is an issue because I need to be able to access my search parameters eventually so I can display my search results.
from flask import Flask, render_template, request
app = Flask(__name__)
@app.route('/')
def home():
return render_template('index.html')
@app.route('/search', methods=['GET'])
def search():
if request.method == 'GET':
#print("hi")
PARAMS= request.args.getlist('q[]')
print(PARAMS)
return render_template('search.html')