I have set up a simple project and when a post request is made, it is expected to return a response depending on what value the user entered.
I am testing my api logic in postman.
At the moment, no matter what value I enter, the same json response is sent back. This is not the expected logic.
views.py:
def function(request):
if request.method == 'POST':
if request.POST.get("number") == 1:
print("Number is 1")
return JsonResponse({'message':'Number is 1'})
else:
print("Number is not 1")
return JsonResponse({'message':'Number is not 1'})
Even if the value of number is equal to 1, the message: Number is not 1, is returned.
Postman request:
{
"number": 1
}
Thank You.
request.POST.get("number") == "1", not 1, but"1"print(request.POST)at the beginning of your function and show us the result?request.body.request.POSTis only used for your own views, and not for webhooks/postman.