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
(message: str, category: str = "message")
| 316 | |
| 317 | |
| 318 | def flash(message: str, category: str = "message") -> None: |
| 319 | """Flashes a message to the next request. In order to remove the |
| 320 | flashed message from the session and to display it to the user, |
| 321 | the template has to call :func:`get_flashed_messages`. |
| 322 | |
| 323 | .. versionchanged:: 0.3 |
| 324 | `category` parameter added. |
| 325 | |
| 326 | :param message: the message to be flashed. |
| 327 | :param category: the category for the message. The following values |
| 328 | are recommended: ``'message'`` for any kind of message, |
| 329 | ``'error'`` for errors, ``'info'`` for information |
| 330 | messages and ``'warning'`` for warnings. However any |
| 331 | kind of string can be used as category. |
| 332 | """ |
| 333 | # Original implementation: |
| 334 | # |
| 335 | # session.setdefault('_flashes', []).append((category, message)) |
| 336 | # |
| 337 | # This assumed that changes made to mutable structures in the session are |
| 338 | # always in sync with the session object, which is not true for session |
| 339 | # implementations that use external storage for keeping their keys/values. |
| 340 | flashes = session.get("_flashes", []) |
| 341 | flashes.append((category, message)) |
| 342 | session["_flashes"] = flashes |
| 343 | app = current_app._get_current_object() # type: ignore |
| 344 | message_flashed.send( |
| 345 | app, |
| 346 | _async_wrapper=app.ensure_sync, |
| 347 | message=message, |
| 348 | category=category, |
| 349 | ) |
| 350 | |
| 351 | |
| 352 | def get_flashed_messages( |