Django - Constantly send output

I want to start processing some files from the django view, and I want them to be able to send the file name to the browser as they are processed. Is there a way to do this (easy)? I could do this with streams and ajax calls, but now I want the simplest solution.

+3
source share
5 answers

I found what I need in response from one of the links provided by Andre Miller.

I found out what can be passed to the HttpResponse iterator, so I used this code and it worked:

def import_iter():
    """ Used to return output as it is generated """
    # First return the template
    t = loader.get_template('main/qimport.htm')
    c = Context()
    yield t.render(c)
    # Now process the files
    if req.method == 'POST':
        location = req.POST['location']
        if location:
            for finfo in import_location(location):
                yield finfo+"<br/>"

return HttpResponse(import_iter())
+6
source

, , .

0

201X

, WebSockets Ajax-!

( ) - Django, StreamingHttpResponse, Django .

https://docs.djangoproject.com/en/dev/ref/request-response/#django.http.StreamingHttpResponse

StreamingHttpResponse Django . , . , CSV.

0

, , Connection: Keep-Alive, , script . Python cgi module cgiprint, , Python , -, script.

-2

Source: https://habr.com/ru/post/1721070/


All Articles