I am trying to catch POST data from a simple form.
This is the first time I am playing around with WSGIREF and I can’t seem to find the correct way to do this.
This is the form: <form action='test' method='POST'> <input type='text' name='name'> <input type='submit'></form>
And the function that is obviously missing the right information to catch post:
def app(environ, start_response): '''starts the response for the webserver''' path = environ[ 'PATH_INFO'] method = environ['REQUEST_METHOD'] if method == 'POST': if path.startswith('/test'): start_response('200 OK',[('Content-type', 'text/html')]) return 'POST info would go here %s' % post_info else: start_response('200 OK', [('Content-type', 'text/html')]) return form()
You should be reading responses from the server.
From nosklo’s answer to a similar problem: ‘PEP 333 says you must read environ[‘wsgi.input’].’
Tested code (adapted from this answer):
Caveat: This code is for demonstrative purposes only.
Warning: Try to avoid hard-coding paths or filenames.