djangoflash.models — Django-Flash model

This module provides the FlashScope class, which provides a simple way to pass temporary objects between views.

FlashScope Class

class djangoflash.models.FlashScope(data=None)

Bases: object

The purpose of this class is to implement the flash, which is a temporary storage mechanism that looks like a Python dictionary, so you can store values associated with keys and later retrieve them.

It has one special property: by default, values stored into the flash during the processing of a request will be available during the processing of the immediately following request. Once that second request has been processed, those values are removed automatically from the storage.

The following operations are supported by FlashScope instances:

len(flash)

Returns the number of items in flash.

flash[key]

Returns the item of flash with key key. Raises a KeyError if key is not found.

flash[key] = value

Sets flash[key] to value.

del flash[key]

Removes flash[key]. Raises a KeyError if key is not found.

key in flash

Returns True if flash has a key key, else False.

key not in flash

Equivalent to not key in flash.

flash.now[key] = value

Sets flash[key] to value and marks it as used.

flash.now(**items)

Puts items into flash and marks those items as used.

flash.now.add(key, *values)

Appends one or more values to key in flash.

add(key, *values)

Appends one or more values to key in this flash.

clear()

Removes all items from this flash.

discard(*keys)

Marks the entire current flash or a single value as used, so when the next request hit the server, those values will be automatically removed from this flash by FlashMiddleware.

get(key, default=None)

Gets the value under the given key. If the key is not found, default is returned instead.

items()

Returns the list of items as tuples (key, value).

iteritems()

Returns an iterator over the (key, value) items.

iterkeys()

Returns an iterator over the keys.

itervalues()

Returns an iterator over the values.

keep(*keys)

Prevents specific values from being removed on the next request. If this method is called with no args, the entire flash is preserved.

keys()

Returns the list of keys.

pop(key, default=None)

Removes the specified key and returns the corresponding value. If key is not found, default is returned instead.

put(**kwargs)

Puts one or more values into this flash.

to_dict()

Exports this flash to a dict.

update()

Mark for removal entries that were kept, and delete unkept ones.

values()

Returns the list of values.

Table Of Contents

Previous topic

Django-Flash overview

Next topic

djangoflash.middleware — Django-Flash middleware

This Page