What is the correct way to stream JSON response from Django? E.g. use 'StreamingHttpResponse` for the following:
def sample_json_view(self):
data = { ... }
resp = http.HttpResponse(content_type="application/json")
json.dump(data, resp)
return resp
My goal is to use StreamingHttpResponse to minimize the latency in the view. Does StreamingHttpResponse offer benefit over HttpResponse where we are writing?
Or: Does writing to file-like HttpResponse object (like with json.dump
) make Django / mod_wsgi to buffer the whole response on the server before starting to stream the response to the client? (increasing latency, all JSON response must be generated first).