I would like to handle an app route url in my Flask project, but unfortunately I can't set it up, because of the HTML form which holds the string, that I need for the proper app route.
My goal is this:
@app.route('/search-<content-from-the-search-form>')
However actually I can't even make it work anyway, (I assume) because the ? that is added by the form. I tried to edit the name tag in the HTML, but it adds a ? and = to the searched string content and couldn't find out how could I remove them.
So now one url looks like this after clicking the Search button:
/domain.com/?search=content-from-textbox
And I would like something like this:
/domain.com/search-content-from-textbox
Possibly somebody could tell me what I'm doing wrong? I can't even figure out if it's HTML only related issue and it can be solved by just editing the form or it needs changes in my flask config file too?
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>
?search=to send queries to the server it totally Ok. If you still want to do it with a path, you have two options: a) use JAvascript on the clients side or use a redirect, which of cause would require two HTTP requests.@app.route('/?search=<content-from-the-search-form>')too, but it doesn't worked, therefore I would better prefer to avoid it.?starts a query string. That's how browsers submit forms that use a GET request (the default). There is no way to accomplish what you want through HTML. You will need to JavaScript to suppress the form submission and redirect the browser to your desired URL.