bor
bor

Reputation: 2351

Read data from HttpResponse using python script

I have one function in Python that returns json as HttpResponse for the client side as:-

def get_response():
    return HttpResponse(json.dumps({'status':1}))

Now from the server itself I want a script to decode the value returned by the function itself and check the status value as:-

check_value = READ_THE_RESPONSE_VALUE(get_response())['status']

How can I do this??

Upvotes: 1

Views: 4068

Answers (1)

avenet
avenet

Reputation: 3043

You can do it this way:

import json

response = get_response()
json_response = json.loads(response.content)
json_response['status']

Upvotes: 5

Related Questions