2👍
You must include the token csrf in the header of the post call
var csrf ='{{ csrf_token }}';
$http({
method: 'POST',
headers: {'X-CSRFToken' : csrf },
url: 'http://127.0.0.1:8000/polls/', // This is the Django server IP
data: {'string': 'body'}
}).then(function successCallback(response) {
$scope.var= "success";
}, function errorCallback(response) {
$scope.var= response; // To display error.
});
}
})
or excempt csrf token for this call
from django.views.decorators.csrf import csrf_exempt
@csrf_exempt
def index(request):
return "true"
0👍
If you have activate cors headers.
from django.views.decorators.csrf import csrf_exempt
@csrf_exempt
def index(request):
return "true"
- [Answered ]-How i can upload an image with CreateView on my post?
- [Answered ]-Why is my Python Django logging file empty when my console log is not?
- [Answered ]-Custom view does not show results in Django Haystack with Elastic Search
- [Answered ]-How to use checkboxes in Django Admin for a ManyToMany field through a model
Source:stackexchange.com