Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

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

Thanks to track user merb for the report.
  • Loading branch information...
commit 24fcca6bddca3db33ac73c29ad9167ac279e4d94 1 parent 9922ed4
Rémy HUBSCHER authored bmispelon committed
Showing with 21 additions and 1 deletion.
  1. +21 −1 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)::
Displaying messages
+.. function:: get_messages(request)
-In your template, use something like::
+**In your template**, use something like::
{% if messages %}
<ul class="messages">
@@ -212,6 +213,25 @@ is a mapping of the message level names to their numeric value::
{% endif %}
+**Outside of templates**, you can use
+ from django.contrib.messages import get_messages
+ storage = get_messages(request)
+ for message in storage:
+ do_something_with_the_message(message)
+For instance, you can fetch all the messages to return them in a
+:ref:`JSONResponseMixin <jsonresponsemixin-example>` instead of a
+:func:`~django.contrib.messages.get_messages` will return an
+instance of the configured storage backend.
The ``Message`` class

0 comments on commit 24fcca6

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