Add documentation about get_messages. #2066

Closed
wants to merge 1 commit into
from

Projects

None yet

2 participants

@bmispelon bmispelon commented on an outdated diff Dec 12, 2013
docs/ref/contrib/messages.txt
@@ -212,6 +212,21 @@ is a mapping of the message level names to their numeric value::
</ul>
{% endif %}
+**In your view,** you can use ``get_messages``::
+
+ 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
+JSONResponse instead of a TemplateResponse.
@bmispelon
bmispelon Dec 12, 2013

You can add internal links for JSONResponse and TemplateResponse.

@bmispelon bmispelon commented on an outdated diff Dec 12, 2013
docs/ref/contrib/messages.txt
@@ -212,6 +212,21 @@ is a mapping of the message level names to their numeric value::
</ul>
{% endif %}
+**In your view,** you can use ``get_messages``::
@bmispelon
bmispelon Dec 12, 2013

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.

@bmispelon bmispelon commented on an outdated diff Dec 12, 2013
docs/ref/contrib/messages.txt
@@ -212,6 +213,25 @@ is a mapping of the message level names to their numeric value::
</ul>
{% endif %}
+
+
+**Outside of templates,** you can use
@bmispelon
bmispelon Dec 12, 2013

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

@bmispelon
Django member

Merged in 24fcca6.

@bmispelon bmispelon closed this Dec 12, 2013
@Natim Natim deleted the peopledoc:ticket_21591_get_messages branch Dec 12, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment