python - Modify query parameters in current GET request for new url -


i access page path /mypage?a=1&b=1&c=1. want create link similar url, parameters changed: /mypage?a=1&b=2&c=1, b changed 1 2. know how current arguments request.args, structure immutable, don't know how edit them. how make new link in jinja template modified query?

write function modifies current url's query string , outputs new url. add function template context can used in jinja templates.

from flask import request werkzeug import url_encode  @app.template_global() def modify_query(**new_values):     args = request.args.copy()      key, value in new_values.items():         args[key] = value      return '{}?{}'.format(request.path, url_encode(args)) 
<a href="{{ modify_query(b=2) }}">link updated "b"</a> 

Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -