- {% endif %}
+**New in Django development version**
-Note that ``RequestContext`` calls ``get_and_delete_messages`` behind the
-scenes, so any messages will be deleted even if you don't display them.
+The ``{{ messages }}`` template variable will also contain session messages.
+For more information, see `django.core.context_processors.messages`_.
-Finally, note that this messages framework only works with users in the user
-database. To send messages to anonymous users, use the `session framework`_.
+.. _django.core.context_processors.messages: ../templates_python/#django-core-context_processors-messages
-.. _session framework: ../sessions/
+Also note that previously, ``RequestContext`` directly called
+``get_and_delete_messages`` behind the scenes, so any messages were deleted even
+if not displayed. Messages are now only deleted if the ``{{ messages }}``
+variable is accessed in a template.
Other authentication sources
============================
Index: docs/templates_python.txt
===================================================================
--- docs/templates_python.txt (revision 6894)
+++ docs/templates_python.txt (working copy)
@@ -295,7 +295,8 @@
("django.core.context_processors.auth",
"django.core.context_processors.debug",
"django.core.context_processors.i18n",
- "django.core.context_processors.media")
+ "django.core.context_processors.media",
+ "django.core.context_processors.messages")
Each processor is applied in order. That means, if one processor adds a
variable to the context and a second processor adds a variable with the same
@@ -345,11 +346,6 @@
logged-in user (or an ``AnonymousUser`` instance, if the client isn't
logged in). See the `user authentication docs`_.
- * ``messages`` -- A list of messages (as strings) for the currently
- logged-in user. Behind the scenes, this calls
- ``request.user.get_and_delete_messages()`` for every request. That method
- collects the user's messages and deletes them from the database.
-
Note that messages are set with ``user.message_set.create``. See the
`message docs`_ for more.
@@ -358,10 +354,13 @@
permissions that the currently logged-in user has. See the `permissions
docs`_.
-.. _user authentication docs: ../authentication/#users
-.. _message docs: ../authentication/#messages
-.. _permissions docs: ../authentication/#permissions
+**New in Django development version**
+Previously, a ``messages`` variable was also added to ``RequestContext``
+containing a list of messages for the currently logged-in user. This
+functionality has been moved to the `django.core.context_processors.messages`_
+context processor.
+
django.core.context_processors.debug
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -409,6 +408,31 @@
`HttpRequest object`_. Note that this processor is not enabled by default;
you'll have to activate it.
+django.core.context_processors.messages
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+If ``TEMPLATE_CONTEXT_PROCESSORS`` contains this processor, every
+``RequestContext`` will contain a variable ``messages``, which is a list of
+messages (as strings) containing any messages for the current session (see
+`session messages`_) or the currently logged-in user (see `auth messages`_).
+
+The messages are not retrieved and cleared (using ``get_and_delete_messages``)
+until the ``messages`` variable is accessed in a template.
+
+Here's an example of template code that displays messages made available by this
+context processor::
+
+ {% if messages %}
+