Home > Enterprise >  How to take requested data as json object in django views?
How to take requested data as json object in django views?

Time:01-19

I'm submitting my form from postman. But i'm getting all key values as a list. I don't know why, how can i get key values without list. here is request.data i'm getting:

{'from_email': ['[email protected]'], 'to_email': ['[email protected]'], 'subject': ['hey man whats up ?'], 'html_body': [<InMemoryUploadedFile: email_test_template.html (text/html)>]}

I'm expecting it to be like following.

{'from_email': '[email protected]', 'to_email': '[email protected]', 'subject': 'hey man whats up ?', 'html_body': <InMemoryUploadedFile: email_test_template.html (text/html)>}

CodePudding user response:

You can write simple loop over it,

response = {'from_email': ['[email protected]'], 'to_email': ['[email protected]'], 'subject': ['hey man whats up ?'], 'html_body': ['seom']}

dummy = dict()
for key, val in response.items():
    dummy[key] = val[0]


print(dummy)

{'from_email': '[email protected]', 'to_email': '[email protected]', 'subject': 'hey man whats up ?', 'html_body': 'seom'}
  •  Tags:  
  • Related