Home / Function/ get_flashed_messages() — flask Function Reference

get_flashed_messages() — flask Function Reference

Architecture documentation for the get_flashed_messages() function in helpers.py from the flask codebase.

Entity Profile

Dependency Diagram

graph TD
  f5befb18_907c_30fb_d596_063142c98775["get_flashed_messages()"]
  881f9803_28d6_7d77_c8d7_1098b41ccf84["helpers.py"]
  f5befb18_907c_30fb_d596_063142c98775 -->|defined in| 881f9803_28d6_7d77_c8d7_1098b41ccf84
  style f5befb18_907c_30fb_d596_063142c98775 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

src/flask/helpers.py lines 347–386

def get_flashed_messages(
    with_categories: bool = False, category_filter: t.Iterable[str] = ()
) -> list[str] | list[tuple[str, str]]:
    """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 form ``(category, message)`` instead.

    Filter the flashed messages to one or more categories by providing those
    categories in `category_filter`.  This allows rendering categories in
    separate html blocks.  The `with_categories` and `category_filter`
    arguments are distinct:

    * `with_categories` controls whether categories are returned with message
      text (``True`` gives a tuple, where ``False`` gives just the message text).
    * `category_filter` filters the messages down to only those matching the
      provided categories.

    See :doc:`/patterns/flashing` for examples.

    .. versionchanged:: 0.3
       `with_categories` parameter added.

    .. versionchanged:: 0.9
        `category_filter` parameter added.

    :param with_categories: set to ``True`` to also receive categories.
    :param category_filter: filter of categories to limit return values.  Only
                            categories in the list will be returned.
    """
    flashes = app_ctx._flashes
    if flashes is None:
        flashes = session.pop("_flashes") if "_flashes" in session else []
        app_ctx._flashes = flashes
    if category_filter:
        flashes = list(filter(lambda f: f[0] in category_filter, flashes))
    if not with_categories:
        return [x[1] for x in flashes]
    return flashes

Subdomains

Frequently Asked Questions

What does get_flashed_messages() do?
get_flashed_messages() is a function in the flask codebase, defined in src/flask/helpers.py.
Where is get_flashed_messages() defined?
get_flashed_messages() is defined in src/flask/helpers.py at line 347.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free