Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Django-Flash is a simple Django extension which provides support for Rails-like flash messages.
Python

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
doc/source
src/djangoflash
.gitignore
LICENSE
README
ez_setup.py
setup.py

README

django-flash
------------

    http://github.com/danielfm/django-flash/tree

Django-flash is a simple extension to the Django framework which enables the
use of the so called flash scope, first introduced by Ruby on Rails a few
years ago.

This is an open source project licenced under the terms of the Lesser General
Public License v3.0 and sponsored by Destaquenet Technology Solutions, a
brazilian software development and consultancy startup.


Installation
------------

The easiest way to install django-flash is via EasyInstall. Follow these
instructions to install EasyInstall if you don’t have it already.

Then, execute the following command line to download and install the latest
stable version from CheeseShop:

    $ sudo easy_install django-flash

If you use git and want to get the latest development version:

    $ git clone git://github.com/danielfm/django-flash.git
    $ cd django-flash
    $ sudo python setup.py install

Or get the latest development version as a tarball:

    $ wget http://github.com/danielfm/django-flash/tarball/master
    $ tar zxf danielfm-django-flash-XXXXXXXXXXXXXXXX.tar.gz
    $ cd danielfm-django-flash-XXXXXXXXXXXXXXXX
    $ sudo python setup.py install


Configuring your Django project
-------------------------------

The first thing to do is plug django-flash to your Django project. To do
this, open your project’s settings.py file and do the following changes:

    TEMPLATE_CONTEXT_PROCESSORS = (
        'djangoflash.context_processors.flash',
    )

    MIDDLEWARE_CLASSES = (
        # django-flash depends on the SessionMiddleware
        'django.contrib.sessions.middleware.SessionMiddleware',
        
        'djangoflash.middleware.FlashMiddleware',
    )

That’s all the required configuration.


Using django-flash
------------------

Once plugged to your project, django-flash automatically adds a flash property
to the HttpRequest objects received by your view methods. This property points
to an instance of djangoflash.models.FlashScope.

Here goes some examples on how to manipulate this scope:

    def my_view(request):
        # Puts a string to the flash scope
        request.flash['key'] = 'value'

        # Same as above
        request.flash.put(key='value')

        # Checks if the object is available at the flash scope
        'key' in request.flash

        # Gets an object from the flash scope
        request.flash['key']

        # Same as above, but returns a default value if the key doesn't exists
        request.flash.get('key', 'default value')

        # Removes an object from the flash scope
        del request.flash['key']


Although we are using plain string values, you are free to use any pickleable
object.


That's just the tip of the iceberg!
-----------------------------------

To learn everything about django-flash, take a look at the the complete
documentation at:

    http://djangoflash.destaquenet.com/


Credits
-------
    Author:  Daniel Fernandes Martins <daniel@destaquenet.com>
    Company: Destaquenet Technology Solutions <http://www.destaquenet.com/>


--EOF
Something went wrong with that request. Please try again.