Google News
logo
Flask - Interview Questions
How to use url_for in the Flask application?
Flask’s url_for function helps in creating dynamic routes. We can make use of url_for in the Flask templates. We can call the view function with parameters and values to generate URLs.
 
For example, pass a function and its arguments, as shown below.
 
<a href=”{{ url_for(‘get_post_id’, post_id=post.id}}”>{{post.title}}<a>

View function for handling variables in routes.
 
@app.route(“/blog/post/<string:post_id>”)
def get_post_id(post_id):
return post_id

 

Advertisement