Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #21591 -- Added documentation about contrib.messages.get_messages.

Refs https://code.djangoproject.com/ticket/21591
Thanks to track user merb for the report.
  • Loading branch information...
commit 24fcca6bddca3db33ac73c29ad9167ac279e4d94 1 parent 9922ed4
authored December 12, 2013 bmispelon committed December 12, 2013

Showing 1 changed file with 21 additions and 1 deletion. Show diff stats Hide diff stats

  1. 22  docs/ref/contrib/messages.txt
22  docs/ref/contrib/messages.txt
@@ -177,8 +177,9 @@ used tags (which are usually represented as HTML classes for the message)::
177 177
 
178 178
 Displaying messages
179 179
 -------------------
  180
+.. function:: get_messages(request)
180 181
 
181  
-In your template, use something like::
  182
+**In your template**, use something like::
182 183
 
183 184
     {% if messages %}
184 185
     <ul class="messages">
@@ -212,6 +213,25 @@ is a mapping of the message level names to their numeric value::
212 213
     </ul>
213 214
     {% endif %}
214 215
 
  216
+
  217
+
  218
+**Outside of templates**, you can use
  219
+:func:`~django.contrib.messages.get_messages`::
  220
+
  221
+    from django.contrib.messages import get_messages
  222
+
  223
+    storage = get_messages(request)
  224
+    for message in storage:
  225
+        do_something_with_the_message(message)
  226
+
  227
+For instance, you can fetch all the messages to return them in a
  228
+:ref:`JSONResponseMixin <jsonresponsemixin-example>` instead of a
  229
+:class:`~django.views.generic.base.TemplateResponseMixin`.
  230
+
  231
+:func:`~django.contrib.messages.get_messages` will return an
  232
+instance of the configured storage backend.
  233
+
  234
+
215 235
 The ``Message`` class
216 236
 ---------------------
217 237
 

0 notes on commit 24fcca6

Please sign in to comment.
Something went wrong with that request. Please try again.