[Answer]-Multiple HttpResponses in Django

1👍

From the Django docs for HttpResponse:

…if you want to add content incrementally, you can use response as a file-like object:

>>> response = HttpResponse()
>>> response.write("<p>Here's the text of the Web page.</p>")
>>> response.write("<p>Here's another paragraph.</p>")

https://docs.djangoproject.com/en/1.7/ref/request-response/#passing-strings

0👍

You would need to pass a list through the context, and then loop over the list in the template. For example:

views.py

def indexview(request):
    data = []
    for item in items_list:
        data.append(item)
    return render(request, 'index.html', {'data': data}

index.html

{% for item in data %}
     {{ item }}
{% endfor %}
👤Hybrid

0👍

I think you want to use the template system. (See Hybrid’s answer).

However, you can pass an iterator, instead of a string to HttpResponse, and if necessary you can stream the results using, StreamingHttpResponse.

def someview(request):
    def mygen(data):  # generator
        for key, value in data.items():
            yield value

    data = {'a': 'Hello', 'b': 'Bye'}
    g = mygen(data)    
    return StreamingHttpResponse(g)
👤monkut

Leave a comment