Write a function that modifies the current url query string and displays a new url. Add a function to global templates using the Flask app template_global application so that it can be used in Jinja templates.
from flask import request from 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>
davidism
source share