[Answered ]-Django/AngularJS: CSFR Token Error

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"
👤Marin

Leave a comment