Issue
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?
Solution
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):
Answered By - FogleBird
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.