Python’s flexible nature means it can bend to almost any application you can imagine and web development is no exception. This article covers simple form handling and creating cookies and presents an example using everything demonstrated.
So far you've seen how you can use Python to get forms data, create cookies and send email... in this last example we'll be using as much of what you've learned here as we can (without going over the top).
#!/usr/bin/env python
import cgi, os, sys
sys.stderr = sys.stdout
def uploads(form, name, path, *args): if form.has_key(name):
#If the form field exists if 'form' then parse the filename to point #at the desired location.
This is pretty small as functions go, but there's quite a lot going on right from the beginning!
As in our other examples, this starts by importing the modules we need into the programs global namespace. Unlike these examples, our next line redirects errors to standard output; this simply sends error messages, as you would get from Python normally to the web browser instead of the error log.