I have a Django site that works on my PC, and was working briefly on my server after loading it on. I noticed my server had Django 1.6 and I upgraded to 1.8.
After rebooting, none of the pages on my site load and I get the error:
ImportError No module named context_processors
I read through the docs on Django and allauth. Django mentions that in 1.8 the context_processors moved and allauth says specific allauth tags are no longer needed in the
TEMPLATE_CONTEXT_PROCESSORS
ofsettings.py
.Django: https://docs.djangoproject.com/en/1.8/ref/settings/
Allauth: https://django-allauth.readthedocs.org/en/latest/installation.html
Anyone else run into this? Am I on the right track? Do I need to change something in settings? I can't really tell if it's a Django or allauth issue so not sure where to start.
Any help is appreciated!
Traceback:
Django Version: 1.8.4 Python Version: 2.7.6 Installed Applications: ('django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'plant', 'journal', 'userimg', 'django.contrib.sites', 'allauth', 'allauth.account') Installed Middleware: ('django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.auth.middleware.SessionAuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware') Traceback: File "/usr/local/lib/python2.7/dist-packages/Django-1.8.4-py2.7.egg/django/core/handlers/base.py" in get_response 132. response = wrapped_callback(request, *callback_args, **callback_kwargs) File "/home/django/django_project/plant/views.py" in plant_main 24. return render(request, 'plant/plant_main.html', context) File "/usr/local/lib/python2.7/dist-packages/Django-1.8.4-py2.7.egg/django/shortcuts.py" in render 67. template_name, context, request=request, using=using) File "/usr/local/lib/python2.7/dist-packages/Django-1.8.4-py2.7.egg/django/template/loader.py" in render_to_string 99. return template.render(context, request) File "/usr/local/lib/python2.7/dist-packages/Django-1.8.4-py2.7.egg/django/template/backends/django.py" in render 74. return self.template.render(context) File "/usr/local/lib/python2.7/dist-packages/Django-1.8.4-py2.7.egg/django/template/base.py" in render 208. with context.bind_template(self): File "/usr/lib/python2.7/contextlib.py" in __enter__ 17. return self.gen.next() File "/usr/local/lib/python2.7/dist-packages/Django-1.8.4-py2.7.egg/django/template/context.py" in bind_template 237. processors = (template.engine.template_context_processors + File "/usr/local/lib/python2.7/dist-packages/Django-1.8.4-py2.7.egg/django/utils/functional.py" in __get__ 60. res = instance.__dict__[self.name] = self.func(instance) File "/usr/local/lib/python2.7/dist-packages/Django-1.8.4-py2.7.egg/django/template/engine.py" in template_context_processors 90. return tuple(import_string(path) for path in context_processors) File "/usr/local/lib/python2.7/dist-packages/Django-1.8.4-py2.7.egg/django/template/engine.py" in <genexpr> 90. return tuple(import_string(path) for path in context_processors) File "/usr/local/lib/python2.7/dist-packages/Django-1.8.4-py2.7.egg/django/utils/module_loading.py" in import_string 26. module = import_module(module_path) File "/usr/lib/python2.7/importlib/__init__.py" in import_module 37. __import__(name) Exception Type: ImportError at /plant/ Exception Value: No module named context_processors
score:13
The issue was that I had no TEMPLATES setting in settings.py as required after upgrading to Django 1.8. I'm not really clear why it was working on my PC using the Django server.
From the allauth docs, I pasted this into my settings file:
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
# Already defined Django-related contexts here
# `allauth` needs this from django
'django.template.context_processors.request',
],
},
},
]
And copied the contents of my old TEMPLATE_DIRS
setting into the DIRS definition for TEMPLATES. The final result looks like this:
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
# Already defined Django-related contexts here
# `allauth` needs this from django
'django.template.context_processors.request',
],
},
},
]
According to the documentation for a recent allauth update, context_processors
now need to be specified in the TEMPLATES setting and not TEMPLATE_CONTEXT_PROCESSORS
setting.
Thanks to Joey Wilhelm for pointing me in the right direction on this.
Similar question
- Django: "No module named context_processors" error after reboot
- ModuleNotFoundError: No module named 'push_notifications' I am getting this error after I've uninstalled the module django push notification
- django import error - No module named core.management
- Django import error - no module named django.conf.urls.defaults
- "No module named simple" error in Django
- Django 1.5b1: executing django-admin.py causes "No module named settings" error
- Django storages: Import Error - no module named storages
- No module named settings_vars error in django debug toolbar
- Widget tweaks error ModuleNotFoundError: No module named 'widget_tweaks' with Django forms
- No module named django error when running any manage.py command in docker with docker-compose
score:1
In my case, I had to delete the following line in settings.py:
'django.core.context_processors.csrf',
I rebooted the server and I didn't see that error again afterwards.
score:1
Now it is updated source: https://docs.djangoproject.com/en/1.11/ref/templates/upgrading/
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
# insert your TEMPLATE_DIRS here
],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
# Insert your TEMPLATE_CONTEXT_PROCESSORS here or use this
# list if you haven't customized them:
'django.contrib.auth.context_processors.auth',
'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',
],
},
},
]
score:2
Just a tip: When a traceback doesn't provide you with the information you need to identify the exact line of code; It can be helpful to enable DEBUG
mode, and open the page in the browser. There's this wonderful little local_vars
element, where you can see local variable state when the traceback occurs. It can be super handy!
(In my case, it was related to changes within allauth)
score:59
I encountered the same problem but I am upgrading from 1.9.1 to 1.10. I found there's a little difference in the settings.
This is the code from 1.9.1
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.core.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
This is code for 1.10
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'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',
],
},
},
]
The line django.core.context_processors.request
is not valid in 1.10. Remove it and the code works well.
Credit To: stackoverflow.com
Related Query
- Django "No Module Named URLs" error
- Django AWS Elastic Beanstalk error ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb
- Django on AWS Elastic Beanstalk - No module named MySQLdb Error
- 'No module named 'encodings'' error when deploying django app on apache with mod_wsgi
- Using Django with virtualenv, get error ImportError: No module named 'django.core.servers.fastcgi'
- Django Channels No module named 'asgiref.sync' error
- django - Error loading MySQLdb module: No module named MySQLdb
- Django error - no module named
- No module named http_client error when trying to run django with django rest framework
- Error while configuring Django with mod_wsgi on Python inside Anaconda: "ImportError: No module named django.core.wsgi"
- django celery: Import error - no module named task
- Why am I getting a "no module named urls" error for django rest framework swagger?
- Django error in urlpatterns: No module named views
- django error - ImportError: No module named apps
- heroku django import error no module named _collections
- Postgres with Django - Improperly configured. Error : ImproperlyConfigured: Error loading psycopg2 module: No module named 'psycopg2'
- Django giving error ImportError: No module named 'corsheaders'
- Could not import/No module named Django Error with Apache
- Django simple Captcha "No module named fields" error
- Django Installation Error (No Module Named Django)
More Query from same tag
- Mock() function gives TypeError in django2
- Error forms django no valid with post
- Django project (apache, mod_wsgi) can't import namespace packages
- Newbie: Django : Adding calculated results to Queryset before passing to template
- How to insert a django user's username in the path via a view?
- Datetime object won't work with weekday()
- Django makemessages to get custom translatable strings
- django giving TypeError when using len() on a QuerySet
- How to use model attribute in both POST and GET in Django
- Deploying two different Django Applications on Windows Server in IIS
- Google Data API authentication
- Get user information in django templates
- Django signals vs. overriding save method
- Django test loading css file
- django template inheritance - views.py for multiple child templates