Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing multiple arguments in return 'Response' (python)

I am working in Angular and I am using Http Request and Response. Is it possible to send multiple arguments in 'Response'.

Angular file:

this.http.get("api/agent/applicationaware").subscribe((data:any)...

python file:

def get(request):
    ...
    return Response(serializer.data)

I want to send multiple arguments in the Response. Like

return Response(serializer.data,obj.someothervalue)

can you help me with this? Thanks in advance :)

like image 292
codebuff Avatar asked Aug 09 '26 05:08

codebuff


2 Answers

You can return a dictionary

return Response({'serializer_data': serializer.data, 'some_other_value': obj.someothervalue})

Or you can append someothervalue to serializer.data

data = serializer.data
data['someothervalue'] = obj.someothervalue
return Response(data)

If obj.someothervalue is a dictionary as well, then you can merge two dictionaries:

data = serializer.data.copy()
data.update(obj.someothervalue)
return Response(data)
like image 176
Harun Yilmaz Avatar answered Aug 10 '26 20:08

Harun Yilmaz


add a dictionary

dict = {}
dict['details'] = serializer.data
dict['other'] = someotherdata
return Response(dict)

hope this helps

like image 42
aNup Avatar answered Aug 10 '26 22:08

aNup