forked from danielfm/django-flash
/
README
103 lines (73 loc) · 2.87 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
django-flash
------------
http://github.com/danielfm/django-flash
django-flash adds a Rails-like flash context support to Django.
Installation
------------
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...
TEMPLATE_CONTEXT_PROCESSORS = (
# other context processors...
'djangoflash.context_processors.flash',
)
MIDDLEWARE_CLASSES = (
# ...other middleware classes...
'django.contrib.sessions.middleware.SessionMiddleware',
'djangoflash.middleware.FlashMiddleware',
# ...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:
<html>
<head>...</head>
<body>
{% if flash %}
<div id="flash_message_panel">
{{ flash }}
</div>
{% endif %}
</body>
</html>
Links
-----
[1] EasyInstall - http://peak.telecommunity.com/DevCenter/EasyInstall
[2] Setuptools - http://pypi.python.org/pypi/setuptools
Authors
-------
Name: Daniel Fernandes Martins <daniel.tritone@gmail.com>
Company: Destaquenet Technology Solutions <http://www.destaquenet.com/>
--EOF