Add a message (with optional category) to the session store. This is typically used to flash a message to a user that will be stored in the session and shown during some other request. For example, .. code-block:: python @app.route('/login', methods=['POST']) async
(message: str, category: str = "message")
| 97 | |
| 98 | |
| 99 | async def flash(message: str, category: str = "message") -> None: |
| 100 | """Add a message (with optional category) to the session store. |
| 101 | |
| 102 | This is typically used to flash a message to a user that will be |
| 103 | stored in the session and shown during some other request. For |
| 104 | example, |
| 105 | |
| 106 | .. code-block:: python |
| 107 | |
| 108 | @app.route('/login', methods=['POST']) |
| 109 | async def login(): |
| 110 | ... |
| 111 | await flash('Login successful') |
| 112 | return redirect(url_for('index')) |
| 113 | |
| 114 | allows the index route to show the flashed messages, without |
| 115 | having to accept the message as an argument or otherwise. See |
| 116 | :func:`~quart.helpers.get_flashed_messages` for message retrieval. |
| 117 | """ |
| 118 | flashes = session.get("_flashes", []) |
| 119 | flashes.append((category, message)) |
| 120 | session["_flashes"] = flashes |
| 121 | app = current_app._get_current_object() # type: ignore |
| 122 | await message_flashed.send_async( |
| 123 | app, _sync_wrapper=app.ensure_async, message=message, category=category |
| 124 | ) |
| 125 | |
| 126 | |
| 127 | def get_flashed_messages( |
searching dependent graphs…