Sep 13
Questions?
The assignment for next week has been posted.
The plan today is to continue discussion of python CGI programming
that we started last time.
There's a lot of material to explore here, and we don't have
a lot of time to do so.
So: what's your pleasure?
- Questions on pieces of this that still seem fuzzy?
- Work on something along these lines together as a class exercise?
- Examples in other programming languages?
$ node
> process.stdout.write("Hello world\n");
> process.env
Here it is (with a few extra TODO comments added in):
#!/usr/bin/env python
#
# sample.cgi
# An example of a python cgi script
# with a form, put/get parameters, and
# (eventually) session management with cookies.
import cgi
# TODO: read session cookie if available;
# set session data from storage.
parameters = cgi.FieldStorage()
if "login" in parameters:
user = " " + parameters["login"].value
# TODO : run user through cgi.escape to sanitize input
# TODO : update stored session with login info
else:
user = ""
# TODO: if "logout" in get/post parameters,
# modify session settings &
# update stored session info
# TODO: create session cookie string and print headers
print "Content-Type: text/html"
print
# TODO: if user is logged in, modify HTML string so that
# (1) form has ogout button &
# (2) 'secret' content is shown.
print """
<!doctype html>
яю1
""" % user