I would like to present a new view after the user submits a search form. I made it as the same way as I do with my other views, but unfortunately this time doesn't happens anything, I can't retrieve the content from the app route. (So this question is not a duplicate of this question, the issue occurs only after submitting the form, it works perfectly in every other situation.) I write something into the form, submit it, then the url changes in the browser, but the view doesn't change anyway. I'm almost sure that it's because the ?
and =
in the search slug, but don't know how should I deal with them in the Python code.
Actually when I submit the form my browser redirects me to an url like this:
http://domain/.com/?search=content+from+textfield
And this is how I tried to catch the content from the search field and present a new view on the Flask's side:
@app.route('/?search=<url_content>', methods=['POST'])
def hello_url(url_content):
return render_template("search-results.html", searchString = url_content])
I would really appreciate if somebody could show me the right way, basically I just wanna retrieve the value of <url_content>
inside the hello_url
function after the search button tapped.
Here's my html:
<form>
<div class="form-group">
<input type="search" class="form-control text-center input-lg" id="inputSearch" name="search" placeholder="search">
</div>
<br>
<div class="text-center"><button type="submit" class="btn btn-primary btn-lg">Search!</button></div>
</form>