[mod_python] mod_python and mod_wsgi

Graham Dumpleton graham.dumpleton at gmail.com
Sat Jul 28 20:08:33 EDT 2007

On 29/07/07, Gert Cuykens <gert.cuykens at gmail.com> wrote:
> How do you do this in wsgi :)
> def handler(req):
>     text = req.read()
>     req.content_type = 'text/xml'
>     req.write(text)
>     return apache.OK


def application(environ, start_response):
    status = '200 OK'

    length = int(environ.get('CONTENT_LENGTH', '0'))
    output = environ['wsgi.input'].read(length)

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

    return [output]

I didn't use text/xml though so I could actually see posted input and
not have browser do something strange.


More information about the Mod_python mailing list