Mod_wsgi returns output buffer instead of return

Right now I have a mod_wsgi script that is structured like this.

def application(environ, start_response):
    status = '200 OK'
    output = 'Hello World!'

    response_headers = [('Content-type', 'text/plain'),
                    ('Content-Length', str(len(output)))]
    start_response(status, response_headers)

    return [output]

I was wondering if anyone knows how to change this to work with the database yieldinstead return, so I can send the page as it is created, and not just after it is completed, so the page loading can go faster for the user.

However, whenever I replace the output for a list and issue it in the application (), it throws an error:

TypeError: sequence of string values expected, value of type list found
+3
source share
3 answers
def application(environ, start_response):
    status = '200 OK'
    output = 'Hello World!'

    response_headers = [('Content-type', 'text/plain'),
                    ('Content-Length', str(len(output)))]
    start_response(status, response_headers)

    yield output

"However, whenever I replace the output for a list and issue it in the application (), it throws an error:"

, . :

for part in mylist:
    yield part

- , :

return mylist

.

+7

, "" , . , "" , . , WSGI , , . Apache/mod_wsgi , Apache . Apache, .

, , ​​. , , . , , . WSGI Content-Length , .

, , . , , , . , , , .

+7

. , Content-Length. , .

def application(environ, start_response):
    status = '200 OK'
    output = 'Hello World!'

    response_headers = [('Content-type', 'text/html')]
    start_response(status, response_headers)

    yield head()
    yield part1()
    yield part2()
    yield part3()
    yield "<!-- bye now! -->"

, , , , - .

, , , , of part2() , (, cookie) - - , , return [output]

http://aaron.oirt.rutgers.edu/myapp/docs/W1200_1200.config_template - , .

0

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


All Articles