0

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 

1 Answer 1

3

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)) ... 
Sign up to request clarification or add additional context in comments.

2 Comments

Currently I'm ending the method with render_template() which has a form, and that form POSTs to a url_for(). I don't seem to be able to pass parameters into the url_for() in the jinja template. Is that expected?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.