Home / Function/ flash() — flask Function Reference

flash() — flask Function Reference

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

Entity Profile

Dependency Diagram

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

Relationship Graph

Source Code

src/flask/helpers.py lines 313–344

def flash(message: str, category: str = "message") -> None:
    """Flashes a message to the next request.  In order to remove the
    flashed message from the session and to display it to the user,
    the template has to call :func:`get_flashed_messages`.

    .. versionchanged:: 0.3
       `category` parameter added.

    :param message: the message to be flashed.
    :param category: the category for the message.  The following values
                     are recommended: ``'message'`` for any kind of message,
                     ``'error'`` for errors, ``'info'`` for information
                     messages and ``'warning'`` for warnings.  However any
                     kind of string can be used as category.
    """
    # Original implementation:
    #
    #     session.setdefault('_flashes', []).append((category, message))
    #
    # This assumed that changes made to mutable structures in the session are
    # always in sync with the session object, which is not true for session
    # implementations that use external storage for keeping their keys/values.
    flashes = session.get("_flashes", [])
    flashes.append((category, message))
    session["_flashes"] = flashes
    app = current_app._get_current_object()
    message_flashed.send(
        app,
        _async_wrapper=app.ensure_sync,
        message=message,
        category=category,
    )

Subdomains

Frequently Asked Questions

What does flash() do?
flash() is a function in the flask codebase, defined in src/flask/helpers.py.
Where is flash() defined?
flash() is defined in src/flask/helpers.py at line 313.
What does flash() call?
flash() calls 1 function(s): _get_current_object.

Analyze Your Own Codebase

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

Try Supermodel Free