Skip to main content

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

aiohttp_session_flash-0.0.3.tar.gz (2.2 kB view details)

Uploaded Source

File details

Details for the file aiohttp_session_flash-0.0.3.tar.gz.

File metadata

File hashes

Hashes for aiohttp_session_flash-0.0.3.tar.gz
Algorithm Hash digest
SHA256 17405586b9fa62c91eb58e087e4facffcc925dc320911f37c086cb7dffa7fa81
MD5 25ad55b9e38d9e3efdcf72dfc9e0bb22
BLAKE2b-256 d511933819313f0aa122fe1a35de801cb76f6a579db9af28c2ebe6fdc1d8ac37

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page