Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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': ['somemail@gmail.com'], 'to_email': ['somemailother@gmail.com'], 'subject': ['hey man whats up ?'], 'html_body': [<InMemoryUploadedFile: email_test_template.html (text/html)>]}

I’m expecting it to be like following.

{'from_email': 'somemail@gmail.com', 'to_email': 'somemailother@gmail.com', 'subject': 'hey man whats up ?', 'html_body': <InMemoryUploadedFile: email_test_template.html (text/html)>}

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can write simple loop over it,

response = {'from_email': ['a@gmail.com'], 'to_email': ['b@gmail.com'], 'subject': ['hey man whats up ?'], 'html_body': ['seom']}

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


print(dummy)

{'from_email': 'a@gmail.com', 'to_email': 'b@gmail.com', 'subject': 'hey man whats up ?', 'html_body': 'seom'}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading