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?
Advertisement
Answer
It takes keyword arguments for the variables:
url_for('add', variable=foo)
url_for('remove', variable=foo)
The flask-server would have functions:
@app.route('/<variable>/add', methods=['GET', 'POST'])
def add(variable):
@app.route('/<variable>/remove', methods=['GET', 'POST'])
def remove(variable):