I have an ajax request, and in django view, i have following prints and outputs.
I have the error in this line and i cant figured it out why.
parsed_json = json.loads(request.body)
I trid to decode request body with utf8 but nothing has changed
AJAX CALL:
$("#add_user_button").click(function (event) {
event.preventDefault();
$.ajax({
type: "POST",
url: '/user/',
data:
{
'action': "addUser",
'username': $('#id_username').val(),
'password': $('#id_password').val(),
'groups': $('#id_groups').val()
}
,
contentType: 'application/json; charset=utf-8',
processData: false,
});
}
DJANGO VIEW PRINTS:
print(request.POST.get("username"))
#print(request.encoding) #returns none
print("Request body is :")
print(request.body)
print(type(request.body))
OUTPUTS:
hello
Request body is :
b'username=hello&password=world&csrfmiddlewaretoken=&addUser=Add+User'
<class 'bytes'>