Package: django-notify
A Django application which provides temporary notifications.Notification messages persist until a request retrieves them.InstallationAdd the middleware to yourMIDDLEWARE_CLASSESsetting (the default
temporary storage relies on Django’scontrib.sessionsapplication, so place
this afterSessionMiddleware):'django_notify.middleware.NotificationsMiddleware',To make it easy to access notifications in templates, add the context processor
into yourTEMPLATE_CONTEXT_PROCESSORSsetting:'django_notify.context_processors.notifications',UsageAdding a notification messageThe middleware attaches an instance of a temporary storage class callednotificationsto yourrequest. To add a notification, call:request.notifications.add('Hello world.')Some other methods provide a standard way to add notifications with commonly
used tags (which are usually represented as HTML classes for the message):request.notifications.debug('%s SQL statements were executed.' % count)
request.notifications.success('Profile details updated.')
request.notifications.warning('Your account expires in three days.')
request.notifications.error('Document deleted.')Displaying notification messagesIn your template, use something like:{% if notifications %}
<ul class="messages">
        {% for message in notifications %}
        <li{% if message.tags %} class="{{ message.tags }}"{% endif %}>{{ message }}</li>
        {% endfor %}
</ul>
{% endif %}If you’re using the context processor, your template should be rendered with aRequestContext. Otherwise, ensurerequest.notificationsis available to
the template context.Expiration of notification messagesThe notifications are marked to be cleared when the storage instance is
iterated (and cleared when the response is processed).To avoid the notifications being cleared, you can setrequest.notifications.used = Falseafter iterating.Notification LevelsTheNOTIFICATIONS_LEVELsetting can be used to change the minimum recorded
level. Attempts to add notifications of a level less than this will be ignored.The built-in levels (which can be imported fromdjango_notifydirectly)
are:ConstantLevelDefault TagDEBUG10debugINFO20SUCCESS25successWARNING30warningERROR40errorINFOis the default minimum recorded level. It is also the
default level of theaddmethod.The minimum recorded level can also be set per request by changing thelevelattribute of the notifications storage instance:import django_notify

# Change the notifications level to ensure the debug message is added.
request.notifications.level = django_notify.DEBUG
request.notifications.debug('Test notification...')

# Set the notifications level back to default.
request.notifications.level = NoneCustom TagsTo provide custom tags for notification levels (either built in levels or
custom ones), set theNOTIFICATIONS_TAGSsetting to a dictionary
containing the levels you wish to change. As this extends the default tags,
you only need to provide tags for the levels you wish to override:import django_notify
NOTIFICATIONS_TAGS = {
    django_notify.INFO: 'info',
    50: 'critical',
}For more direct control over message tags, you can optionally provide a string
containing extra tags to any of the add methods:request.notifications.add('Over 9000!', extra_tags='dragonball')
request.notifications.error('Email box full', extra_tags='email')Extra tags are added before any default tag for that level (space separated).Temporary Storage BackendsDjango notify can use different backends to store temporary messages. To change
which backend is being used, add aNOTIFICATIONS_STORAGEto your settings,
referencing to the module and class of the storage class. For example:NOTIFICATIONS_STORAGE = 'cookie.CookieStorage'Django Notify first looks for the module inside ofdjango_notify.storage,
and if not found, tries to import the full given module directly.Three temporary storage classes are included in Django Notify:'session.SessionStorage'This class stores all messages inside of the request’s session. It
requires Django’scontrib.sessionapplication.'cookie.CookieStorage'This class stores the notification data in a cookie (signed with a secret
hash to prevent manipulation) to persist notifications across requests.
Old messages are dropped if the cookie data size would exceed 4096 bytes.'fallback.FallbackStorage'This is the default temporary storage class.This class uses CookieStorage for all notification messages, falling back
to using SessionStorage for the messages which could not fit in a single
cookie.Since it is uses SessionStorage, it also requires Django’scontrib.sessionapplication.To write your own, subclass theBaseStorageclass indjango_notify.storage.baseand write_getand_storemethods.