Login

Tag "messages"

Snippet List

SessionMessages

Creates a message list, but unlike the messaging system in django.contrib.auth it is session-persistent and can therefor be displayed after a redirect.

  • messages
  • sessionstore
Read More

Extended rails flash implementation

This is an extendend version of the Rails Flash implementation by Sean Patrick Hogan that supports different message types. **Setting a flash message:** request.flash.error = 'Item could not be saved' request.flash['error'] = 'Item could not be saved' request.flash['foo'] = 'bar' **Displaying a flash in the view:** <!-- show the error message --> {% if flash.error %}An error occured:{{ flash.error }}{% endif %} <!-- just show the first message found --> {% if flash %}An error occured:{{ flash }}{% endif %} <!-- show all messages --> {% for msg in flash %}{{ msg.type }}: {{ msg.msg }}{% endfor %} Note that it still works with simple strings as well. Feel free to just use it like this: request.flash = "Message" And: {% if flash %}{{ flash }}{% endif %} However, be aware that once you did this, you destroyed the Flash() dict and thus lost the extended functionality. You can use request.flash.clear() to remove all messages.

  • flash
  • messages
  • rails
Read More

2 snippets posted so far.