Reputation: 773
I'm trying to use django-cors-headers to add CORs to my server, but when I load the page I receive this error on the server.
ImproperlyConfigured: Error importing module corsheaders.middleware.CorsMiddlewaredjango.middleware.common: "No module named CorsMiddlewaredjango.middleware.common"
I've installed the cors-header app using pip:
pip install django-cors-headers
And my settings.py file is configured this way:
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'social.apps.django_app.default',
'corsheaders',
'dashboard',
)
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'corsheaders.middleware.CorsMiddleware'
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
CORS_ORIGIN_ALLOW_ALL = True
I'm using python 2.7 version.
Upvotes: 5
Views: 8133
Reputation: 55197
You're missing a comma after 'corsheaders.middleware.CorsMiddleware'
in your MIDDLEWARE_CLASSES
.
Add one.
Your issue is caused by the fact that Python is concatenating the strings 'corsheaders.middleware.CorsMiddleware'
and 'django.middleware.common.CommonMiddleware'
and is therefore trying to import commonMiddleware
from corsheaders.middleware.CorsMiddlewaredjango.middleware.common'
.
Upvotes: 19