Messages通过一个[中间件](https://docs.djangoproject.com/en/1.10/ref/middleware/)实现,并和[上下文处理器](https://docs.djangoproject.com/en/1.10/ref/templates/api/)相对应。
通过**django-admin startproject**创建的默认**settings.py**文件,已经包含了启用message功能的所有所需设置:
* [**INSTLLED_APPS**](https://docs.djangoproject.com/en/1.10/ref/settings/#std:setting-INSTALLED_APPS)中配置**'django.contrib.messages'**。
* [**MIDDLEWARE**](https://docs.djangoproject.com/en/1.10/ref/settings/#std:setting-MIDDLEWARE)中包含**'django.contrib.sessions.middleware.SessionMiddleware'**和**'django.contrib.messages.middleware.MessageMiddleware'**
默认的[存储后端](https://docs.djangoproject.com/en/1.10/ref/contrib/messages/#message-storage-backends)是基于[sessions](https://docs.djangoproject.com/en/1.10/topics/http/sessions/)。这就是为什么**SessionMiddleware**必须要启用,并且在[**MIDDLEWARE**](https://docs.djangoproject.com/en/1.10/ref/settings/#std:setting-MIDDLEWARE)列表中,要排在**MessageMiddleware**之前。
* 在[**TEMPLATES**](https://docs.djangoproject.com/en/1.10/ref/settings/#std:setting-TEMPLATES)中定义的**DjangoTemplates**后端**'context_processors'**选项中,需要包含**'django.contrib.messages.context_processors.messages'**。
如果你不想使用messages,你可以从[**INSTAALED_APPS**](https://docs.djangoproject.com/en/1.10/ref/settings/#std:setting-INSTALLED_APPS)中移除**'django.contrib.messages'**,从[**MIDDLEWARE**](https://docs.djangoproject.com/en/1.10/ref/settings/#std:setting-MIDDLEWARE)中移除**MessageMiddleware**那一行,以及从[**TEMPLATES**](https://docs.djangoproject.com/en/1.10/ref/settings/#std:setting-TEMPLATES)中移除**messages**上下文处理器