James Gardner: Home > Work > Code > FlashMessage > 0.1.0 > API Documentation

FlashMessage v0.1.0 documentation

API Documentation

Flash message service

Userd for storing a flash message in a cookie so that the result of an action performed before an HTTP redirect can be displayed to the user on the page they end up seeing.

The code doesn’t use Python’s cookie support (which always appeared over-complex) and instead uses a simple URL encoding scheme that allows all unicode characters to be safely encoded in the cookie.

The maximum length of the message is 4070 characters assuming you use the default allowed message types and only the letters a-z, A-Z, 0-9 and _. Any other characters (or message types with a name longer than ‘good’) will use more space when encoded in the cookie so you won’t get quite so many characters. You can also use Unicode characters but again the message itself has to be slightly shorter because of the encoding used.

To read a flash message you would do this:

print flow.flash.message
print flow.flash.message_type

If no flash message is present, flow.flash.message and flow.flash.message_type will be None.

To set a flash message you’d do this:

flow.flash.set('Hi there!', message_type='good')

If you call flow.flash.set() without a message_type, the first allowed message type is used (which by default is 'good').

Once the flash message is set, reading it will return the set messages, not the original ones from the request. If you don’t remove the flash message it will be present on the next request too.


The messages you set will be stored client-side in the cookie so could be ready by any other application on the same domain or by anyone with access to the user’s browser’s cookie store. Don’t store passwords or other sensitive data in the flash message.

The module also contains a commented-out version of a Middleware component from an earlier implementation, left in the source code on the off chance it might be useful later on.

exception flashmessage.FlashMessageError
class flashmessage.FlashMessageService(cookie_name='flash', allowed_message_types=[, 'good', 'normal', 'error'])
static config(flow, name)
static create(flow, name, config)
start(flow, name)
stop(flow, name)
flashmessage.encode_flash(message, message_type, allowed_message_types)
James Gardner: Home > Work > Code > FlashMessage > 0.1.0 > API Documentation