Using the messages framework

When allowing users to interact with your platform, there are many cases where you might want to inform them about the result of their actions. Django has a built-in messages framework that allows you to display one-time notifications to your users.

The messages framework is located at django.contrib.messages and is included in the default INSTALLED_APPS list of the settings.py file when you create new projects using python manage.py startproject. You will note that your settings file contains a middleware named django.contrib.messages.middleware.MessageMiddleware in the MIDDLEWARE settings.

The messages framework provides a simple way to add messages to users. Messages are stored in a cookie by default (falling ...

Get Django 2 by Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.