The previous post made use of the Django messages framework to display a one-time message after an HTTP redirect.
Using the messages framework is simple. First, as explained in the docs, adjust your settings file:
- ‘django.contrib.messages’ is in INSTALLED_APPS
- MIDDLEWARE_CLASSES contains ‘django.contrib.sessions.middleware.SessionMiddleware’ and ‘django.contrib.messages.middleware.MessageMiddleware’
- TEMPLATE_CONTEXT_PROCESSORS contains ‘django.contrib.messages.context_processors.messages’
You can now use the framework in a view:
And display it within a template: