summaryrefslogtreecommitdiff
path: root/examples/helloworld/index.py
diff options
context:
space:
mode:
authorIan Bicking <ian@ianbicking.org>2005-04-22 02:44:48 +0000
committerIan Bicking <ian@ianbicking.org>2005-04-22 02:44:48 +0000
commit6f5aacfa56deae47a2bfa9c60bb77947432c9810 (patch)
tree887f7b87f167a988566657304331ba8bb15ed4d6 /examples/helloworld/index.py
downloadpaste-git-6f5aacfa56deae47a2bfa9c60bb77947432c9810.tar.gz
Renamed WSGIKit to Paste
Diffstat (limited to 'examples/helloworld/index.py')
-rw-r--r--examples/helloworld/index.py28
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')