python - Django CORS X-FirePHP 版本

标签 python django cors django-cors-headers

当我尝试访问端点时收到以下错误消息。

Request header field X-FirePHP-Version is not allowed by Access-Control-Allow-Headers in preflight response.

这就是我的 settings.py 文件的样子

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'rest_framework',
    'api.apps.ApiConfig',
    'django_server',
    'corsheaders',  # For Cross-Origin Resource Sharing
]

CORS_ORIGIN_ALLOW_ALL = True
CORS_ALLOW_CREDENTIALS = False

最佳答案

如果您在向启用 CORS 的服务器发出的请求中包含其他 header ,则应在 CORS_ALLOW_HEADERS django-cors 中指定这些 header 。环境。这应该可以解决这个问题,但我会仔细检查以确保这些 header 应该存在。

# In your project's settings.py

CORS_ALLOW_HEADERS = (
    'x-requested-with',
    'content-type',
    'accept',
    'origin',
    'authorization',
    'x-csrftoken',
    'x-firephp-version',  # Added to default list
)

# more settings...

在底层,这只是在服务器响应上设置 Access-Control-Request-Headers header 。

关于python - Django CORS X-FirePHP 版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38649170/

相关文章:

python - 如何在 Pandas 的字符串末尾添加特定数量的字符?

python - Django ImageField upload_to 路径

python - Django 中有没有办法直接从模型获取当前经过身份验证的用户?

django - 我如何在 django 中提出禁止响应

javascript - AWS CORS 问题 : Ajax response comes as Error even after getting 200 status code

javascript - Ajax 请求因 Origin 'null' 而被拒绝,origin 是相同的并且不在本地主机或本地文件上

python - pandas DataFrame 从 MultiIndex 日期索引中获取每年的第一天

python - *.npy Windows 阅读器

Python Pandas - 如何格式化和拆分列中的文本?

jquery - IE11 的 CORS 请求