aiohttp_session_flash
The library provides flash messages for aiohttp.web on top of aiohttp_session.
“Flash messages” are simply a queue of string messages (or other JSON-serializable objects) stored in the session.
Installation
pip install aiohttp_session_flash
Usage
Add session_middleware and aiohttp_session_flash.middleware to the list of app’s middleware:
app = web.Application(
middlewares=[
aiohttp_session.session_middleware(EncryptedCookieStorage(b'x'*32)),
aiohttp_session_flash.middleware,
]
)
Within the handler, pull and push flash messages as needed:
from aiohttp import web
from aiohttp_session_flash import flash, pop_flash
async def foo(request):
flash(request, "Hello")
flash(request, ["This", "works", "too"])
return web.Response(body=b'Flashed some messages')
async def bar(request):
for message in pop_flash(request):
print(message)
return web.Response(body=b'OK')
Template context processor
The template context processor is provided for template libraries that can use it:
aiohttp_mako_context_processors.setup(app, [
...
aiohttp_session_flash.context_processor,
])
<ul>
% for message in get_flashed_messages():
<li>${message}</li>
% endfor
</ul>
Contributing
Running tests
pip install -r requirements_test.txt pytest
Metadata
Release files for aiohttp_session_flash 0.0.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| aiohttp_session_flash-0.0.4.tar.gz | 2.2 kB | Details |
Release files / aiohttp_session_flash-0.0.4.tar.gz
| Download URL | aiohttp_session_flash-0.0.4.tar.gz |
|---|---|
| Size | 2.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1d39915567e3f0cf759d75f736cb8e7afc75aed124b85e8f0c673b6f86df1b0f
|
|
BLAKE2b-256 checksum How to use checksums |
4d17d6cf47e736ea7e1a8bd08915b6de179fc6c922e9bba4a16cb7a9393c7f72
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |