100 | | === django-notify === |
101 | | django-notify is the current front-runner in terms of technical features so a sampling of the potential API is included below. Feel free to include the API(s) of other solutions as well for comparison. It is understood that, should django-notify be chosen, this may (and probably will) change prior to inclusion in the core. |
102 | | |
103 | | Add the middleware to your MIDDLEWARE_CLASSES setting (after !SessionMiddleware): |
104 | | {{{ |
105 | | 'django_notify.middleware.NotificationsMiddleware', |
106 | | }}} |
107 | | |
108 | | Add the context processor into your TEMPLATE_CONTEXT_PROCESSORS setting: |
109 | | {{{ |
110 | | 'django_notify.context_processors.notifications', |
111 | | }}} |
112 | | |
113 | | Add a temporary notification message like this: |
114 | | {{{ |
115 | | request.notifications.add('Hello world.') |
116 | | # You can optionally provide a string containing tags (which is usually represented as HTML classes for the message). |
117 | | request.notifications.add('Your rating is over 9000!', 'error') |
118 | | }}} |
119 | | |
120 | | Use notifications in your template: |
121 | | {{{ |
122 | | {% if notifications %} |
123 | | <ul class="notifications"> |
124 | | {% for message in notifications %} |
125 | | <li{% if message.tags %} class="{{ message.tags }}"{% endif %}>{{ message }}</li> |
126 | | {% endfor %} |
127 | | </ul> |
128 | | {% endif %} |
129 | | }}} |
130 | | |