[Tutor] HTML form post to Python script, without server
kent37 at tds.net
Tue Mar 29 14:17:28 CEST 2005
Bill Kranec wrote:
> This might be slightly OT, but I hope I can get a few pointers. Is it
> possible to have an HTML form pass values to a Python script on a local
> computer, and execute that script? (I'm running Win XP, if that matters.)
You have to have a server process running. It can be on your local computer, you don't need a
separate server machine.
Running a web server with CGI support on your PC is as simple as
- open a DOS shell
- cd to a directory containing a cgi-bin directory
- python -c "import CGIHTTPServer; CGIHTTPServer.test()"
Now of course you have to write a CGI script to handle the data. See the docs for the cgi module and
the guides listed here for help:
Important note! There is a bug (gasp!) in the os module in Python 2.4 that breaks CGIHTTPServer; if
you want to do this with Python 2.4 you should download the 2.4.1c2 release.
> I would like to set up such a form to do some data entry. I understand
> that a GUI is probably a better way to do what I want, but thought this
> way might be quicker.
If you are comfortable with HTML and CGI then this could be faster. Though I don't think you have to
know much about Tkinter to put up a simple data entry screen.
> Is this as simple as having the form action point to my script, and
> using the input names as my variables? Or am I not thinking about this
No, not quite that simple. You need the server to find the script and run it.
More information about the Tutor