Skip to content
Advertisement

Error in making POST request to django API

From post man, I’m trying to make POST request to an order API created using django restframework but I’m getting the following error:

JavaScript

The specific point where the error is located is specified in the error but I find difficulty constructing VALID json for the request body. Here is how I’m making the request on postman:

JavaScript

Here is the program:

JavaScript

The view I’, trying to test is shown below:

JavaScript

Any hint on this is well appreciated

Advertisement

Answer

I think the payload is not correct. Now the whole product data is uploaded, but it should be changed into the product_id. Because in the view, it is being considered as the id field like Product.objects.get(id=i['product']).

So the solution is like the following. First, the payload should be changed.

JavaScript

And in the addOrderItems function,

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement