Skip to main content

UNKNOWN

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.

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>

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.1.tar.gz (2.1 kB view details)

Uploaded Source

File details

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

File metadata

File hashes

Hashes for aiohttp_session_flash-0.0.1.tar.gz
Algorithm Hash digest
SHA256 b66e178a446bf9b0e2182c5d60ea5bb78439ec3cddbbcd82b8a7388dcd7a2f30
MD5 6f6b6db14dc48807659c50a667a6de27
BLAKE2b-256 e9b5d6912f5396560291bb7e12ed41bf72f900741269d3d8a5df60de0b8ee432

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