I am trying to fetch response from a Django API using react, but the key value pair which I am passing is not visible in the response.
React fetch code
handleClick(i) {
.
.
.
if (i != '=') {
.
.
}
else {
// CODE TO FETCH FROM DJANGO API
fetch('http://127.0.0.1:8000/solve/', {
method: 'POST',
body: {"expression":this.state.content}
}).then((response)=>{ console.log(response)})
}
}
Python Code
# Create your views here.
@api_view(["POST"])
def solveExpression(expression_json):
try:
math_expr = expression_json.data["expression"]
result = eval(math_expr)
data = {"result":result} #This is the data I want to send to reactjs
return JsonResponse(data)
except Exception as e:
return JsonResponse("Error:" + str(e), safe = False)
But unfortunately the response I get doesn't have the key "result" in it.
Kindly correct me where I am committing the mistake as I am quiet new to reactjs.
