kelorek
kelorek

Reputation: 6214

Flask -- pass arguments to outgoing url.

Some of my endpoints of my flask api use values from an html form to determine what data to return. I'd like to pass the parameters that I use to generate the data I'm returning back to the URL rendered in the browser. Is there a way to do that with flask?

Example:

http://example.com/search

On the page, the user types the word "duck" into a search box, hits go, and in addition to the results, Flask returns url showing all the parameters I passed into the api underneath the application... e.g:

http://example.com/search?&search_term=duck&page=0&per_page=20

Upvotes: 0

Views: 1992

Answers (1)

atupal
atupal

Reputation: 17240

You can use url_for to generate the url:

from flask import redirect, url_for, request
...
# duck = request.form.get('search_term')
return redirect(url_for('search', search_term=duck, page=0, per_page=20))
...

Upvotes: 3

Related Questions