Pulls all flashed messages from the session and returns them. Further calls in the same request to the function will return the same messages. By default just the messages are returned, but when `with_categories` is set to ``True``, the return value will be a list of tuples in the f
(
with_categories: bool = False, category_filter: t.Iterable[str] = ()
)
| 350 | |
| 351 | |
| 352 | def get_flashed_messages( |
| 353 | with_categories: bool = False, category_filter: t.Iterable[str] = () |
| 354 | ) -> list[str] | list[tuple[str, str]]: |
| 355 | """Pulls all flashed messages from the session and returns them. |
| 356 | Further calls in the same request to the function will return |
| 357 | the same messages. By default just the messages are returned, |
| 358 | but when `with_categories` is set to ``True``, the return value will |
| 359 | be a list of tuples in the form ``(category, message)`` instead. |
| 360 | |
| 361 | Filter the flashed messages to one or more categories by providing those |
| 362 | categories in `category_filter`. This allows rendering categories in |
| 363 | separate html blocks. The `with_categories` and `category_filter` |
| 364 | arguments are distinct: |
| 365 | |
| 366 | * `with_categories` controls whether categories are returned with message |
| 367 | text (``True`` gives a tuple, where ``False`` gives just the message text). |
| 368 | * `category_filter` filters the messages down to only those matching the |
| 369 | provided categories. |
| 370 | |
| 371 | See :doc:`/patterns/flashing` for examples. |
| 372 | |
| 373 | .. versionchanged:: 0.3 |
| 374 | `with_categories` parameter added. |
| 375 | |
| 376 | .. versionchanged:: 0.9 |
| 377 | `category_filter` parameter added. |
| 378 | |
| 379 | :param with_categories: set to ``True`` to also receive categories. |
| 380 | :param category_filter: filter of categories to limit return values. Only |
| 381 | categories in the list will be returned. |
| 382 | """ |
| 383 | flashes = request_ctx.flashes |
| 384 | if flashes is None: |
| 385 | flashes = session.pop("_flashes") if "_flashes" in session else [] |
| 386 | request_ctx.flashes = flashes |
| 387 | if category_filter: |
| 388 | flashes = list(filter(lambda f: f[0] in category_filter, flashes)) |
| 389 | if not with_categories: |
| 390 | return [x[1] for x in flashes] |
| 391 | return flashes |
| 392 | |
| 393 | |
| 394 | def _prepare_send_file_kwargs(**kwargs: t.Any) -> dict[str, t.Any]: |