0 votes
in Python Flask by
How to use url_for in the Flask application?

1 Answer

0 votes
by
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

Related questions

0 votes
asked Dec 24, 2022 in Python Flask by sharadyadav1986
0 votes
0 votes
asked Dec 24, 2022 in Python Flask by sharadyadav1986
...