I am trying to post some data from AngualrJS to a Django backend.
My code looks like this:
angular
$http({
method: 'POST',
url: 'path/to/django/',
data: $scope.formData,
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
}
});
django view
import json
class MyView(View):
def post(self, request):
body = json.loads(request.body)
# Do stuff
However, the json
module complains:
TypeError: the JSON object must be str, not 'bytes'
Why is the data not sent as JSON and how should I best convert the payload to a Python object?