priya vyas priya vyas - 3 months ago 36x
Python Question

Django ImportError: No module named middleware

I am using Django version 1.8 and python 2.7. I am getting the following error after running my project.

Traceback (most recent call last):
File "C:\Python27\lib\wsgiref\", line 85, in run
self.result = application(self.environ, self.start_response)
File "C:\Python27\lib\site-packages\django\contrib\staticfiles\", line 63, in __call__
return self.application(environ, start_response)
File "C:\Python27\lib\site-packages\django\core\handlers\", line 170, in __call__
File "C:\Python27\lib\site-packages\django\core\handlers\", line 50, in load_middleware
mw_class = import_string(middleware_path)
File "C:\Python27\lib\site-packages\django\utils\", line 26, in import_string
module = import_module(module_path)
File "C:\Python27\lib\importlib\", line 37, in import_module
ImportError: No module named middleware
[26/Aug/2015 20:34:29] "GET /favicon.ico HTTP/1.1" 500 59

This is my file

Django settings for collageapp project.

Generated by 'django-admin startproject' using Django 1.8.

For more information on this file, see

For the full list of settings and their values, see

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os

APP_PATH = os.path.dirname(os.path.abspath(__file__))
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

# Quick-start development settings - unsuitable for production
# See

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '******************************************************'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True


# Application definition




ROOT_URLCONF = 'collageapp.urls'

'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'context_processors': [

WSGI_APPLICATION = 'collageapp.wsgi.application'

# Database

'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'college_app',
'USER': 'root',
'HOST': 'localhost', # Or an IP Address that your DB is hosted on
'PORT': '3306',

# Internationalization



USE_I18N = True

USE_L10N = True

USE_TZ = True

# Static files (CSS, JavaScript, Images)

STATIC_URL = '/static/'

I have tried surfing the error but in vain. My same code is working fine in other machine.


Open up a python shell by running python shell in your project directory.

Run the following commands one at a time in the python shell:

>>> from corsheaders.middleware import CorsMiddleware
>>> from oauth2_provider.middleware import OAuth2TokenMiddleware
>>> from django.contrib.auth.middleware import SessionAuthenticationMiddleware

One of the lines should give you an error like the following:

Traceback (most recent call last):
  File "<console>", line 1, in <module>
ImportError: No module named middleware

The line that gives you that error is the missing module that is giving you the problem.

To find the path where the modules are searched, do

>>> import sys; sys.path

Alternatively, if you don't know how to use the python shell, you could just remove the following lines in your settings.MIDDLEWARE_CLASSES one at a time until you don't get that error anymore:


Just reinstall the package that gave you the error.

django.contrib.auth.middleware -> django

corsheaders.middleware -> corsheaders

oauth2_provider.middleware -> oauth2_provider