Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Add documentation about get_messages. #2066

Closed
wants to merge 1 commit into from

2 participants

Natim Baptiste Mispelon
docs/ref/contrib/messages.txt
... ...
@@ -212,6 +212,21 @@ is a mapping of the message level names to their numeric value::
212 212
     </ul>
213 213
     {% endif %}
214 214
 
  215
+**In your view,** you can use ``get_messages``::
  216
+
  217
+    from django.contrib.messages import get_messages
  218
+
  219
+    storage = get_messages(request)
  220
+    for message in storage:
  221
+        do_something_with_the_message(message)
  222
+
  223
+For instance, you can fetch all the messages to return them in a
  224
+JSONResponse instead of a TemplateResponse.
1
Baptiste Mispelon Owner

You can add internal links for JSONResponse and TemplateResponse.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
docs/ref/contrib/messages.txt
... ...
@@ -212,6 +212,21 @@ is a mapping of the message level names to their numeric value::
212 212
     </ul>
213 213
     {% endif %}
214 214
 
  215
+**In your view,** you can use ``get_messages``::
1
Baptiste Mispelon Owner

Technically, it's not limited to just views (you can use it anywhere you have a request object) so I'd use "Outside of templates" or something like that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
docs/ref/contrib/messages.txt
... ...
@@ -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
1
Baptiste Mispelon Owner

For consistency, the comma should be outside of the bold markup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Baptiste Mispelon
Owner

Merged in 24fcca6.

Baptiste Mispelon bmispelon closed this December 12, 2013
Natim Natim deleted the branch December 12, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Dec 12, 2013
Fixed #21591 -- Added documentation about contrib.messages.get_messages.
Refs https://code.djangoproject.com/ticket/21591
Thanks to track user merb for the report.
526612e
This page is out of date. Refresh to see the latest.

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
 
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.