Python POST data using mod_wsgi

前端 未结 2 1930
灰色年华
灰色年华 2020-12-15 07:40

This must be a very simple question, but I don\'t seem to be able to figure out.

I\'m using apache + mod_wsgi to host my python application, and I\'d like to get the

2条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-15 07:54

    PEP 333 says you must read environ['wsgi.input'].

    I just saved the following code and made apache's mod_wsgi run it. It works.

    You must be doing something wrong.

    from pprint import pformat
    
    def application(environ, start_response):
        # show the environment:
        output = ['
    ']
        output.append(pformat(environ))
        output.append('
    ') #create a simple form: output.append('
    ') output.append('') output.append('') output.append('
    ') if environ['REQUEST_METHOD'] == 'POST': # show form data as received by POST: output.append('

    FORM DATA

    ') output.append(pformat(environ['wsgi.input'].read())) # send results output_len = sum(len(line) for line in output) start_response('200 OK', [('Content-type', 'text/html'), ('Content-Length', str(output_len))]) return output

提交回复
热议问题