I have a search bar on my Flask powered website which works well when the user clicks the search button (I am using a JS code with a POST
request). However it doesn't work when the user sends the form with an 'enter' click. In those cases the browser loads a link like this /?finder=searchedword
.
The finder
is the value of the name
attribute of the html code used for the form. In order to solve the problem, I have tried to setup a redirect that always redirects to the proper link that should be loaded, but unfortunately using this solution doesn't work. It just simply redirects to the main page "/"
.
This is how I manage the redirect:
@app.route("/?finder=<tag>")
def search(tag):
t = tag.replace(' ', '-')
return redirect("/result/%s/" % (t,), code=301)
My question is what would be the proper technique to handle this type of redirection? This kind of redirection always works for me and I am using it in several apps, therefore I have no idea what is the weak part of the implementation.