Enabling CORS request (cross-education request) in Django

I am trying to use the overpass API http://wiki.openstreetmap.org/wiki/Overpass_API with JavaScript XMLHttpRequest in a project running on Django, but I keep getting further

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://www.google.com/accounts/ClientLogin. (Reason: CORS header 'Access-Control-Allow-Origin' missing). 

error. I get this error regardless of whether I use GET or POST, as well as from any other host, and not just the transition APIs.

I installed django-cors-headers https://github.com/ottoyiu/django-cors-headers and followed the instructions there by setting the corsherists in INSTALLED_APPS and the corsheads .middleware.CorsMiddleware ',' django.middleware.common. CommonMiddleware 'in MIDDLEWARE_APPS and I set

 CORS_ORIGIN_ALLOW_ALL = true 

in settings.py but nothing works. I run it locally with

 python manage.py runserver 

but I also accept it in openhift. In neither of these works do they both give the error above.

Please let me know if I am not missing anything here.

+5
source share
1 answer

I had the same problem trying to access my Django Rest Framework API hosted on Heroku from my laptop ( localhost ). I am using Django 1.10.2 , DRF 3.4.7 and python v3.4 .

I did pip install django-cors-headers (version 1.2.2) and configured it as docs and then repeated the same error again :(

Keep looking for a watch and then it hit me!

I did pip install django-cors-middleware (version 1.3.1) without removing the django-cors-headers package. Also, I did not touch things in my settings.py file (it was configured as django-cors-headers settings, although these two packages do not have a lot of differences - the latter is the plug of the first).

The update hit (from localhost) and everything works brilliantly!

Now I managed to get the data from myapp.herokuapp.com through the jQuery ajax method.

+4
source

All Articles