Django rest and angularjs error cors

1

I'm using django rest and angularjs 1.x in a project, in case this backend and frontend project are isolated, I'm using a gulp server to run angularjs, but when I try to access the api rest through the $http.get of the angle, the browser returns me the following error:

XMLHttpRequest cannot load 0.0.0.0:8000/api/clients/?format=json. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.

Yes, I'm using Chrome, I thought the error was in the browser, so I went to Firefox, but it continued the same way, I also tried to use django-cors only, unfortunately I did not succeed with it, some solution both here in the stack and google in general but did not have a favorable return.

Has anyone ever had this kind of problem? if yes how to solve this empasse?

I'm grateful already.

    
asked by anonymous 23.07.2016 / 03:35

2 answers

1

The problem is that requests must be from the same source when you use a XmlHttpRequest request.

You need to configure the application that provides the data to accept the source from which you are trying to capture the request (the application made in angular ).

You can use the Django Cors Headers library for requests to no longer have this error.

Related:

What is the meaning of CORS?

    
04.08.2016 / 18:08
0

Install Cors on django:

pip install django-cors-headers  

Then in settings.py, put it in your apps:

INSTALLED_APPS = [
..............
'corsheaders',
]

And finally still in settings.py:

CORS_ORIGIN_ALLOW_ALL = True
    
31.08.2017 / 21:30