Thursday, 4 January 2024

django request/response documentation - how to return a json object

 https://docs.djangoproject.com/en/5.0/ref/request-response/

https://www.w3schools.com/python/ref_requests_response.asp



 from django.http import HttpResponse
response.headers["Age"] = 120

json()Try itReturns a JSON object of the result (if the result was written in JSON format, if not it raises an error)
response.json()

return httpresponse with JSON string
json.dumps(response.json())

HttpResponse(content=json.dumps(resp), content_type='application/json')

No comments:

Post a Comment