Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'django.contrib.messages.context_processors.messages' must be enabled in DjangoTemplates

Tags:

django

When I try to migrate or createsuperuser in my project I get this error.

SystemCheckError: System check identified some issues:

ERRORS:
?: (admin.E404) 'django.contrib.messages.context_processors.messages' must be enabled in DjangoTemplates (TEMPLATES) in order to use the admin application.

I shouldn't be getting error since it's a starter project and I'm not even using templates. This parameter 'django.contrib.messages.context_processors.messages' is present in settings.py, TEMPLATES

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',
            ],
        },
    },
]

Can the issue be from a third-part app, since I added one called 'tinymce' to my INSTALLED_APPS https://github.com/aljosa/django-tinymce

like image 627
Saadat Avatar asked Oct 29 '25 21:10

Saadat


1 Answers

Enabling messages

Messages are implemented through a middleware class and corresponding context processor.

The default settings.py created by django-admin startproject already contains all the settings required to enable message functionality:

'django.contrib.messages' is in INSTALLED_APPS.

MIDDLEWARE contains 'django.contrib.sessions.middleware.SessionMiddleware' and 'django.contrib.messages.middleware.MessageMiddleware'.

The default storage backend relies on sessions. That’s why SessionMiddleware must be enabled and appear before MessageMiddleware in MIDDLEWARE.

The 'context_processors' option of the DjangoTemplates backend defined in your TEMPLATES setting contains 'django.contrib.messages.context_processors.messages'.

If you don’t want to use messages, you can remove 'django.contrib.messages' from your INSTALLED_APPS, the MessageMiddleware line from MIDDLEWARE, and the messages context processor from TEMPLATES.

More about: https://django.readthedocs.io/en/2.1.x/ref/contrib/messages.html

like image 160
Diego Vinícius Avatar answered Oct 31 '25 11:10

Diego Vinícius



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!