Vlad Schnakovszki
Vlad Schnakovszki

Reputation: 8601

"No module named context_processors" After Upgrade

I've upgraded Django from version 1.8 to version 1.10 and I am now getting the below error:

No module named context_processors

This is in relation to this code in settings.py. If I comment out the lines that start with 'django.core it runs fine but I obviously will be losing functionality:

TEMPLATES = [
{
    'BACKEND': 'django.template.backends.django.DjangoTemplates',
    'DIRS': [
        TEMPLATE_PATH,
    ],
    'APP_DIRS': True,
    'OPTIONS': {
        'debug': DEBUG,
        'context_processors': [
            ...
            'django.core.context_processors.debug',
            'django.core.context_processors.i18n',
            'django.core.context_processors.media',
            'django.core.context_processors.static',
            'django.core.context_processors.tz',
            'django.contrib.messages.context_processors.messages',
            ...
    ],
    },
},
]

How can I fix this?

Note: This, this and this are all similar but nothing Google returns addresses this issue.

Upvotes: 0

Views: 926

Answers (1)

Vlad Schnakovszki
Vlad Schnakovszki

Reputation: 8601

After a lot of digging, I found a fix. Hidden in the documentation is the solution to the issue:

django.core.context_processors

Built-in template context processors have been moved to django.template.context_processors.

Hence, in order to fix the issue, you need to replace django.core with django.template. The code would then look like this:

TEMPLATES = [
{
    'BACKEND': 'django.template.backends.django.DjangoTemplates',
    'DIRS': [
        TEMPLATE_PATH,
    ],
    'APP_DIRS': True,
    'OPTIONS': {
        'debug': DEBUG,
        'context_processors': [
            ...
            'django.template.context_processors.debug',
            'django.template.context_processors.i18n',
            'django.template.context_processors.media',
            'django.template.context_processors.static',
            'django.template.context_processors.tz',
            'django.contrib.messages.context_processors.messages',
            ...
    ],
    },
},
]

Upvotes: 4

Related Questions