-1

The following error is being thrown by my Django code on my VPS when I try to use messages:

You cannot add messages without installing django.contrib.messages.middleware.MessageMiddleware

Exception Type: MessageFailure Exception Value:
You cannot add messages without installing django.contrib.messages.middleware.MessageMiddleware

I do have all the appropriate settings in my settings.py file. My VPS is running Django 1.9.6. The same error is not thrown when I run the code locally on my laptop. On my laptop, I have Django 1.10.3 running. Are there any differences in the treatment of messages between Django 1.9.6 and 1.10.3 that would cause this to happen? It seems that on Django 1.9.6 my settings in settings.py are being ignored.

Relevant code in settings.py is as follows:

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',

]

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',

]

Any help would be greatly appreciated. Thanks.

Foobar
  • 843
  • 1
  • 10
  • 23

1 Answers1

1
INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

follow the code with the order of each

Exprator
  • 26,992
  • 6
  • 47
  • 59
  • I tried your order and it didn't make a difference. – Foobar Jun 23 '17 at 15:59
  • Any other suggestions? It's not the order of the settings or the settings themselves, but rather that the settings are not taking affect on the VPS. – Foobar Jun 23 '17 at 16:12
  • Are there any alternatives to using messages in Django? – Foobar Jun 23 '17 at 16:36
  • Is it related to this article? https://stackoverflow.com/questions/11938164/why-dont-my-django-unittests-know-that-messagemiddleware-is-installed. I ask because this bug was specific to Django 1.4 but I'm not sure if it was fixed until 1.10. – Foobar Jun 23 '17 at 17:12