diff options
Diffstat (limited to 'examples/helloworld/index.py')
-rw-r--r-- | examples/helloworld/index.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/examples/helloworld/index.py b/examples/helloworld/index.py new file mode 100644 index 0000000..b79132f --- /dev/null +++ b/examples/helloworld/index.py @@ -0,0 +1,28 @@ +""" +WSGI application + +Automated greeting application. +""" + +import cgi + +def application(environ, start_response): + form = cgi.FieldStorage(fp=environ['wsgi.input'], + environ=environ, + keep_blank_values=1) + start_response('200 OK', [('Content-type', 'text/html')]) + + if form.getvalue('name'): + yield ('<html><head><title>Hello!</title></head>\n') + yield ('<body>\n') + yield ('<h1>Hello %s!</h1>\n' % form['name'].value) + else: + yield ('<html><head><title>Who is there?</title></head>\n') + yield ('<body>\n') + yield ('<h1>Who is there?</h1>\n') + yield ('<form action="%s" method="POST">\n' % environ['SCRIPT_NAME']) + yield ('What is your name?<br>\n') + yield ('<input type="text" name="name" value="%s"><br>\n' + % cgi.escape(form.getvalue('name', ''), 1)) + yield ('<input type="submit" value="That is my name"></form>\n') + yield ('</body></html>\n') |