【问题标题】:How enable cors for html files?如何为 html 文件启用 cors?
【发布时间】:2020-06-15 02:36:06
【问题描述】:

我正在使用 cloudfront 从 S3 存储桶分发我的静态文件。我使用 django 作为我的后端。我配置了我的云端以从我的 S3 存储桶中获取我的静态文件。对于 imagescssjs 文件效果很好。但是对于html 文件却出现了这个错误:

Access to XMLHttpRequest at 'https://xxxxxxxx.cloudfront.net/static/partials/main.html?v=e720c74cfb39a5d17a1f5b4d75a496df30620a5c' from origin 'https://www.xxxxxxx.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

但问题是我的其他文件下载正常,为什么我的 html 文件出现这些错误。

我的 pip 中安装了 django-cors-headers==1.1.0,并且我启用了所有 CORS_ORIGIN_ALLOW_ALL = True。但仍然出现错误。

【问题讨论】:

    标签: django cors amazon-cloudfront


    【解决方案1】:

    您介意发布您的settings.py 配置吗?

    除了您已采取的步骤之外,还需要将'corsheaders' 添加到您的INSTALLED_APPS'corsheaders.middleware.CorsMiddleware'MIDDLEWARE顶部

    祝你好运!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-06-28
      • 2014-01-19
      • 2015-08-13
      • 2020-12-27
      • 2015-07-22
      相关资源
      最近更新 更多