I have an Django application that is exposing data using the Django-rest-framework. I can access my objects in json format like this:
curl http://localhost:8000/cemeteries/
or
curl http://localhost:8000/cemeteries/2/
I am now trying to use AngularJS to access the data.I opted for restangular, which seemed simple enough. I have configured restangular as such:
demoApp.factory('CbgenRestangular', function(Restangular) {
return Restangular.withConfig(function(RestangularConfigurer) {
RestangularConfigurer.setBaseUrl('http://localhost:8000');
});
});
And then in my controller:
demoApp.controller('SimpleController', function($scope, simpleFactory, CbgenRestangular, $location){
$scope.customers = [];
CbgenRestangular.all("cemeteries/").getList().then(function() {
console.log("All ok");
}, function(response) {
console.log("Error with status code", response.status);
});
The problem is that in my Django logs, I always see an HTTP OPTIONS request:
[14/Aug/2013 12:24:12] "OPTIONS /cemeteries/ HTTP/1.1" 200 10245
In Firebug it says "Error with status code 0".
Any idea what am I doing wrong? Thanks in advance for your help!
Regards, Phil
It's possible that the reason you're seeing the OPTIONS
request is due to the browser making a pre-flight CORS request. If that is the case you probably want to take a look at https://github.com/ottoyiu/django-cors-headers which is known to play nicely with REST framework.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments