Modify query parameters in current GET request for new url
Write a function that modifies the current url's query string and outputs a new url. Add the function to the template globals using your Flask app's template_global
decorator so that it can be used in Jinja templates.
from flask import requestfrom werkzeug.urls import url_encode@app.template_global()def modify_query(**new_values): args = request.args.copy() for key, value in new_values.items(): args[key] = value return '{}?{}'.format(request.path, url_encode(args))
<a href="{{ modify_query(b=2) }}">Link with updated "b"</a>