I try use $http.delete with Django and get HTTP 403. My JS file below:
var myApp = angular.module('myApp',['ui.bootstrap']);
myApp.run(function($http) {
$http.defaults.headers.post['X-CSRFToken'] = $.cookie('csrftoken');
});
myApp.controller('PostsListController', ['$scope','$http',function($scope,$http) {
$http.get('/api/v1/posts/').success(function (data) {
$scope.posts = data;
});
$scope.deletePost = function(post) {
$http.delete('/api/v1/posts/'+ post.id + '/');
};
}]);
detail from console:
{detail: "CSRF Failed: CSRF token missing or incorrect."}
detail
:
"CSRF Failed: CSRF token missing or incorrect."
csrftokenthat you can retrieve from a HTTP response, which varies depending on the language that is being used.. More: docs.djangoproject.com/en/dev/ref/csrf/#ajax