Session flash messages for aiohttp.web
Project description
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
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Close
Hashes for aiohttp_session_flash-0.0.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 07d98319a3659f7ac9c606fbbc6db46ddac9f8f8c3f21f04c0cea3429a9e91e3 |
|
MD5 | f0e1f9d0c95094a2b449ce06d59ff3b3 |
|
BLAKE2b-256 | 910f935a316bf3ac81cd0d66f8e1559e1b237a19c0e35245e253f561db8e82d2 |