I'm spending hours to solve this problem. The problem is I can't send POST's body data. I'm getting 500 error from the server.
Here is my HTTP request on React Native (I'm thinking I may have wrong axios request). There might be problem on http body?
export const createCloth = (token, hType, clothObject) => async dispatch => {
let headers = { 'Authorization': `JWT ${token}`};
if(hType==1) {
headers = { 'Authorization': `JWT ${token}`};
} else if (hType==2) {
headers = { 'Authorization': `Bearer ${token}`};
}
let {image, text, clothType, ... , onlyMe} = clothObject;
console.log(text); <- printing ok
console.log(bigType); <- printing ok
let response = await axios.post(`${ROOT_URL}/clothes/create/`, {
text, clothType, ..., onlyMe
}, {headers});
console.log(response.data); <<< 500 HTTP error
Here is my part of Backend API.
class ClothCreateAPIView(APIView):
def post(self, request, format=None):
# Create Cloth
# self.request.POST.get('user_id')
print('--------REQUEST-------')
print(request)
logged_in_user = self.request.user
content = self.request.POST.get('text')
cloth_type = self.request.POST.get('clothType')
only_me = self.request.POST.get('onlyMe')
...
print('----------PRINTING CLOTH CONTENT')
print(logged_in_user) <- printing my username (GOOD)
print(cloth_type) <- printing None always (BAD)
print(content) <- printing None always (BAD)
print(self.request.POST) <- prints <QueryDict: {}>
At the last two line, why are they always printing None? I'm checking these syntax back and forth more than twenty times. This is so frustrating
Nothing wrong with self.request.POST.get('somthing') syntax but the reason why it's not working is we have problem on the syntax of axios request