I have a problem with my code.I'm working with API now, and when I call it, it will show me some result. And I want to show a loading text like this : "300: Calculating" to know that my code is processing , untill the result show out , the "300: Calculating " text will disappear. And my code is in a def function. My codeis roughly as below :
@api_view(['POST'])
def Measurementwarning_response():
i = 0
while i < 3:
if i == 1:
message_code = "300: Calculating"
predict_response1 = {
"message_code": message_code,
}
predict_response = predict_response1
return HttpResponse(json.dumps(predict_response))
if i == 2:
message_code = "200. Sucessfully : Hello world"
predict_response2 = {
'message_code': message_code,
}
predict_response = predict_response2
time.sleep(2)
return HttpResponse(json.dumps(predict_response))
i = i +1
I hope that after I call this API (Measurementwarning_response). The loading text "300: Calculating" will show out like this : This loading text "300: Calculating" will exisit whithin 2 seconds
End then, after 2 seconds, the result "200. Sucessfully : Hello world" will show out. And "300: Calculating" text will disappear like this This is the result will show out after 2 seconds and the "300: Calculating" text will disappear
I have been tried to make a while loop and return HttpResponse(json.dumps(predict_response)) 2 times. But it seems to be that I can not return 2 times in a function.I have been tried many times but I still can not do it. I hope you guys will take a look and comment in below to let me know what should I do with my code. Thank you guys so much