Django项目部署后CORS错误

问题描述 投票:0回答:1

我的 Pyton Django 项目和我的项目在本地服务器上工作,但是当我在服务器上部署时,我收到此错误。我使用 IIS 管理器进行部署。其他数据库连接必须工作,因为我可以访问其他 API。顺便说一句,我的用户是超级用户。

Access to XMLHttpRequest at 'https://website.websites.com:8000/integration/sync' from origin 
'https://website.website.com' has been blocked by CORS policy: No 'Access-Control-                
Allow-Origin'header is present on the requested resource.
And here is my API;POST https://website.website..com:8000/integration/sync net::ERR_FAILED 500 
(Internal Server  Error) 

顺便说一句,其他 API 运行没有问题

我搜索错误,他们建议我更改setting.py,但下面是我的设置;

ALLOWED_HOSTS = ['*']
CORS_ALLOW_ALL_ORIGINS = True
CORS_ALLOW_CREDENTIALS = True 
MIDDLEWARE = [
'corsheaders.middleware.CorsMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',

 I use for deployment IIS may be its about it.
 So they said that its about Autontication 

IIS 我尝试了所有组合,但仍然不起作用,

python django iis cors
1个回答
0
投票

在未启用 cors 的情况下,您是否会遇到相同的错误?也许你也可以尝试在 web.config 文件中添加以下配置来启用 cors。

<system.webServer>  
  <httpProtocol>  
    <customHeaders>  
        <add name="Access-Control-Allow-Origin" value="*" />  
        <add name="Access-Control-Allow-Methods" value="GET,POST,OPTIONS" />  
        <add name="Access-Control-Allow-Headers" value="Content-Type, soapaction" />  
    </customHeaders>  
  </httpProtocol>  
</system.webServer>  

如果这不起作用,请尝试使用失败的请求跟踪来查看有关500错误的详细信息,这将生成详细的日志文件,这将帮助您识别问题。

© www.soinside.com 2019 - 2024. All rights reserved.