[Answer]-Django – iterating over return render_to_response

1👍

You can actually do this, by making your function a generator – that is, using ‘yield’ to return each line.

However, you would need to create the response directly, rather than using render to response.

0👍

render_to_response will render the first batch to the website and stop. Then the website must call this view again somehow if you want to send the next batch. You will also have to maintain a record of where you were in the log file so that the second batch can be read from that point.
I assume that you have some logic in the templates so that the second post to render_to_response doesnt overwrite the first
If your data is not humongous, you should explore sending over the entire contents you want to show on the webpage each time you read some new lines.

👤zaphod

0👍

Instead of re-inventing the wheel, use django_logtail

Leave a comment