redirecting with url_for to a path with query params in flask

Any extra keyword parameters passed to url_for() which are not supported by the route are automatically added as query parameters.

For repeated values, pass in a list:

<a href="https://stackoverflow.com/questions/23143827/{{ url_for("stats', chart=[new_chart, other_chart]) }}>View More</a>

Flask will then:

  1. find the stats endpoint
  2. fill in any required route parameters
  3. transform any remaining keyword parameters to a query string

Demo, with 'stats' being the endpoint name for /:

>>> url_for('stats', chart=['foo', 'bar'])
'/?chart=foo&chart=bar'

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)