Django CORS 'Access-Control-Allow-Origin'

2

I'm trying to redirect a Django View function to a page in PHP, currently hosted on my own computer.

The fact is that I've seen that it gives me a crossover error because I'm calling another link from my own team.

I have found a module called django-cors-headers and I have configured it as it comes in the documentation link

    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

After the end of the function I pass the url but I still get the same error

return HttpResponseRedirect('http://localhost/pruebas/prueba.php',{'datos':datos})

and this is the answer:

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').
    
asked by F Delgado 29.01.2018 в 10:05
source

1 answer

3

You're doing it the other way around, CORS works like this:

  • You have server A, from where you load a page with JS into your browser.
  • Said JS tries to access server B through AJAX.
  • In this scenario it is B who has to implement CORS to explicitly accept calls from server A code.

        
    answered by 29.01.2018 / 10:28
    source