我正在尝试将 Django View 函数重定向到当前托管在我自己的机器上的 PHP 页面。
事实是,我已经看到它给了我一个跨域错误,因为我正在调用我自己团队的另一个链接。
我找到了一个名为 django-cors-headers 的模块,我已经按照文档https://github.com/ottoyiu/django-cors-headers中的内容对其进行了配置
MIDDLEWARE = [
'corsheaders.middleware.CorsMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
]
CORS_ORIGIN_ALLOW_ALL = True
CORS_ALLOW_CREDENTIALS = False
然后在函数结束时我传递了 url 但它仍然给我同样的错误
return HttpResponseRedirect('http://localhost/pruebas/prueba.php',{'datos':datos})
这就是答案:
Solicitud desde otro origen bloqueada: la política de mismo origen
impide leer el recurso remoto en http://localhost/pruebas/prueba.php
(razón: falta la cabecera CORS 'Access-Control-Allow-Origin').
你倒着做,CORS 是这样工作的:
在这种情况下,B 必须实现 CORS 以显式接受来自服务器 A 代码的调用。