Rails-like flash context support for Django
Switch branches/tags
Nothing to show
Pull request Compare This branch is 1 commit ahead, 180 commits behind danielfm:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.




django-flash adds a Rails-like flash context support to Django.


The easiest way to install django-flash is via EasyInstall[1]. Follow these[2]
instructions to install EasyInstall if you don't have it already.

Then, execute the following command line to install the latest stable version
of django-flash:

    $ 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

Using django-flash

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:

# ...some settings...
    # other context processors...

    # ...other middleware classes...
    # ...more middleware classes...
# ...more settings...

After doing that all HttpRequest objects received by your views will have an
extra attribute called 'flash' in which you can store the data you want to
be available to the next request.

Here goes an example on how to actually use the the flash context:

# ...some views...
def some_view(request):
    # ...do some work here...
    if success:
        # There are several ways to use the 'flash' context
        request.flash = 'Success'
        request.flash['some_key'] = MyObject()
        request.flash.some_key = ['an', 'array', 'here']
    return HttpResponseRedirect('http://some/url/')
# ...more views...

Os dados que forem inseridos no contexto flash poderão ser acessados na próxima requisição. Por exemplo, o código abaixo mostra como acessar os dados do contexto flash a partir de um template HTML: 

Whatever you put in it will become available to the next request. For example,
the code below shows how to access data stored in the 'flash' context from a
HTML template:

        {% if flash %}
            <div id="flash_message_panel">
                {{ flash }}
        {% endif %}


[1] EasyInstall      - http://peak.telecommunity.com/DevCenter/EasyInstall
[2] Setuptools       - http://pypi.python.org/pypi/setuptools


Name:    Daniel Fernandes Martins <daniel.tritone@gmail.com>
Company: Destaquenet Technology Solutions <http://www.destaquenet.com/>