Sometimes, we want to pass arguments into redirect(url_for()) of Flask.
In this article, we’ll look at how to pass arguments into redirect(url_for()) of Flask.
How to pass arguments into redirect(url_for()) of Flask?
To pass arguments into redirect(url_for()) of Flask, we define the destination route to get the request parameters.
Then we can call url_for
with the parameters.
For instance, we write
@app.route("/found/<email>/<list_of_objects>")
def found(email, list_of_objects):
return render_template("found.html", keys=email, obj=list_of_objects)
to add the /found/<email>/<list_of_objects>
route that maps to the found
function.
In it, we get the the URL parameters from the found
function’s parameters.
Then in another route, we write
return redirect(url_for("found", email=x, list_of_objects=y))
to call url_for
with the route name and the parameters to return the URL for the /found/<email>/<list_of_objects>
route with the parameters filled in.
Then we call redirect
with the URL to redirect to the /found/<email>/<list_of_objects>
route.
Conclusion
To pass arguments into redirect(url_for()) of Flask, we define the destination route to get the request parameters.
Popular Posts
- Show / Hide div based on dropdown selected using jQuery
- Autosuggestion Select Box using HTML5 Datalist, PHP and MySQL with Example
- Custom Authentication Login And Registration Using Laravel 8
- Infinite Scrolling on PHP website using jQuery and Ajax with example
- How to Convert MySQL Data to JSON using PHP
- Google Login or Sign In with Angular Application
- How to change date format in PHP?
- Image Lazy loading Using Slick Slider
- Slick Slider Basic With Example
- php in_array check for multiple values
- Adaptive Height In Slick Slider
- Slick Slider Center Mode With Example
- How to Scroll to an Element with Vue 3 and ?
- JavaScript Multiple File Upload Progress Bar Using Ajax With PHP
- Slick Slider Multiple Items With Example