[Answer]-How to get actual value from HttpResponse in view?

1๐Ÿ‘

โœ…

So what you are saying is you need to return two things (an HttpResponse and the status value) from your google function instead of just one thing.

In this case you should return a tuple, eg:

def google(request, objectId):
    google = {}
    google['status'] = 1
    response = HttpResponse(json.dumps(google))  # <-- should be string not dict
    return response, google

def process_view(request):
    dspAction = {}
    try:
        response, google = google(request, objectId)
        if google['status'] == int(1):
            #some function
    except:
        dspAction['Google Status'] = "Google Action Completed"
    return HttpResponse(json.dumps(dspAction),content_type='application/json')
๐Ÿ‘คAnentropic

0๐Ÿ‘

return HttpResponse(google.status)

EDIT from comment:
To use the other attributes in the dictionary you need to pass the context variables, usually with render.

# view.py
from django.shortcuts import render
... 
return render(request, "template.html", {'google':google})


# template.html
# you can then access the different attributes of the dict
{{ google }} {{ google.status }} {{ google.error }} 
๐Ÿ‘คawwester

Leave a comment