Gio Borje Gio Borje - 6 months ago 27
Python Question

Create dynamic URLs in Flask with url_for()

Half of my Flask routes requires a variable say,

/<variable>/add
or
/<variable>/remove
. How do I create links to those locations?

url_for()
takes one argument for the function to route to but I can't add arguments?

Answer

It takes keyword arguments for the variables:

url_for('add', variable=foo)