You can use Python/Django to receive streaming responses and collect them all into a single StreamingHttpResponse using the following steps:
from django.http import StreamingHttpResponse
def my_view(request):
# Your view logic here
response = StreamingHttpResponse(streaming_content=...)
return response
def my_generator():
# Your generator logic here
yield b'Chunk 1 of data'
yield b'Chunk 2 of data'
yield b'Chunk 3 of data'
response = StreamingHttpResponse(streaming_content=my_generator())
responses = []
for i in range(10):
# Your view logic here
response = StreamingHttpResponse(streaming_content=...)
responses.append(response)
def combined_generator(responses):
for response in responses:
for chunk in response.streaming_content:
yield chunk
response = StreamingHttpResponse(streaming_content=combined_generator(responses))
response = StreamingHttpResponse(streaming_content=combined_generator(responses))
return response
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2023-01-20 11:00:00 +0000
Seen: 14 times
Last updated: Jan 12 '23
How can I set up Gunicorn with a Django Project?
Looking for a Python Module that finds Tags for a Text describing its Content
Need a Function in Python to remove entries less than 2 digits from an Array
How can I convert a Document in Python?
How can I program a Loop in Python?
How can I enable Python Code Highlighting in Askbot?