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(f)
Returns the number of items in the flash f.
f[key]
Returns the item of f with key key. Raises a KeyError if key is not in the flash f.
f[key] = value
Sets f[key] to value.
del f[key]
Removes f[key] from f. Raises a KeyError if key is not in the map.
key in f
Returns True if f has a key key, else False.
key not in f
Equivalent to not key in f.
f.now[key] = value
Sets f[key] to value and marks it as used.
f.now(**items)
Puts the given items into f and marks them as used.
add(key, value)
Appends a value to a 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.
has_key(key)

Returns True if there’s a value under the given key.

Deprecated since version 1.4.2: has_key() is deprecated in favor of key in f.

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.
put_immediate(key, value)
Puts a value inside this flash and marks it as used.
to_dict()
Exports this flash to a dict.
update()

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

Note

This method is called automatically by djangoflash.middleware.FlashMiddleware when a HTTP request hits the server, so never call this method yourself, unless you have a very good reason to do so.

values()
Returns the list of values.

Table Of Contents

Previous topic

Django-Flash overview

Next topic

djangoflash.middleware — Django-Flash middleware

This Page