I have in my views.py :
from django.shortcuts import render
from django.http import StreamingHttpResponse
import time
def home(request):
return render(request, 'home.html', {})
def automate_run(request):
response = StreamingHttpResponse(automate_foo(), content_type="application/json")
response['Cache-Control'] = 'no-cache'
return response
def automate_foo():
for i in range(1, 11):
status = "Step %d" % i
percentage = i * 10
json_string = f'[{{"status": "{status}","percentage": "{percentage}"}}]'
print(json_string)
yield json_string
time.sleep(.5)
This works smoothly on my localhost on Windows 11 with apache2 and macOS Ventura with apache2 showing 1,2,3 … 10 one after the other every half second. But on my server at https://yield.anjanesh.com it outputs the JSON in console after 5 seconds in one go and not streaming to the HTML page.
I checked this on 2 servers, one on Azure with nginx where I set proxy_buffering off but still no streaming.
How is this working on locahost and not on my server(s) ?