Django cors header 和服务器错误

标签 django cors pip middleware django-cors-headers

我正在尝试使用 django-cors-headers 将 COR 添加到我的服务器,但是当我加载页面时,我在服务器上收到此错误。

ImproperlyConfigured: Error importing module corsheaders.middleware.CorsMiddlewaredjango.middleware.common: "No module named CorsMiddlewaredjango.middleware.common"

我已经使用 pip 安装了 cors-header 应用程序:
pip install django-cors-headers

我的 settings.py 文件是这样配置的:
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

我正在使用 python 2.7 版本。

最佳答案

您的 'corsheaders.middleware.CorsMiddleware' 中的 MIDDLEWARE_CLASSES 后缺少逗号。

加一个。

您的问题是由 Python 连接字符串 'corsheaders.middleware.CorsMiddleware''django.middleware.common.CommonMiddleware' 并因此尝试从 commonMiddleware 导入 o​​jit_code 引起的。

关于Django cors header 和服务器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31277708/

相关文章:

带有 anchor (#)参数的 Django 重定向()

asp.net-web-api - WebAPI OWIN SelfHosting CORS 支持

javascript - 使用 CORS 测试 firebase HTTPS 调用

python - pip install pyinstaller 没有名为 pyinstaller 的模块

python-2.7 - 无法安装PIP Windows

python - 从 Django View 中的按钮获取点击事件

mysql - 获取总和为特定值的第一个 mysql 数据库记录

python - 如何比较python中的时间跨度?

javascript - 处理响应 - SyntaxError : Unexpected end of input when using mode: 'no-cors'

python - 在 Windows 中使用 pip