Accumulate a list of messages to show at the next page request.
This class is useful when you want to redirect to another page and also show a status message on that page, such as “Changes saved” or “No previous search found; returning to home page”.
THIS IMPLEMENTATION DEPENDS ON PYLONS. However, it can easily be adapted for another web framework.
Normally you instantiate a Flash object in myapp/lib/helpers.py:
from webhelpers.pylonslib import Flash as _Flash
flash = _Flash()
The helpers module is then imported into your controllers and templates as h. Whenever you want to set a message, do this:
h.flash("Record deleted.")
You can set additional messages too:
h.flash("Hope you didn't need it.")
Now make a place in your site template for the messages. In Mako you might do:
<% messages = h.flash.pop_messages() %>
% if messages:
<ul id="flash-messages">
% for message in messages:
<li>${message}</li>
% endfor
</ul>
% endif
You can style this to look however you want:
ul#flash-messages {
color: red;
background-color: #FFFFCC;
font-size: larger;
font-style: italic;
margin-left: 40px;
padding: 4px;
list-style: none;
}
Powered by Pylons - Contact Administrators
Comments (1)
from webhelpers.tools import Flash as _Flash
should be
from webhelpers.pylonslib import Flash as _Flash
Suggest an addition to the docs, or report errors. Note that we will delete documentation fixes as they're applied.
You must login before you can comment.