Skip to main content

QueryString

The query string of the current page route, available as Page.query.

It is parsed from Page.route on every access, so it can be read in main() as well as in a Page.on_route_change handler. For example, with the route /products?id=1&sort=price:

  • page.query.get("id") returns "1";
  • page.query.to_dict returns {"id": "1", "sort": "price"};
  • page.query.path returns "/products".

Values are always strings. To navigate to a route with a query string, pass the parameters as keyword arguments to Page.navigate or Page.push_route.

Inherits: flet.controls.query_string.UrlComponents

Properties

  • path - Return the path component of the current page route, without the query string and fragment.
  • to_dict - Parse the query component of the current page route into a dictionary.

Methods

  • get - Return the value of the query parameter key in the current page route.
  • post - Build an encoded querystring from key-value pairs.

Properties​

pathproperty​

path: str

Return the path component of the current page route, without the query string and fragment.

to_dictproperty​

to_dict: dict

Parse the query component of the current page route into a dictionary.

The route is read on every access, so the result always matches Page.route. Keys and values are percent-decoded, with + decoded as a space. Parameters without a value, such as debug in ?debug or ?debug=, are left out. When a key appears more than once, its last non-empty value is returned.

Methods​

get​

get(key: str) -> str

Return the value of the query parameter key in the current page route.

Parameters:

  • key (str) - The name of the query parameter.

Returns:

  • str - The decoded value. When key appears more than once, its last non-empty value.

Raises:

  • KeyError - If the route has no query parameter key with a non-empty value.

post​

post(kwargs: dict)

Build an encoded querystring from key-value pairs.

Returns:

  • A querystring that starts with ? and is ready to append to a URL.