|
| 1 | +<HTML> |
| 2 | +<HEAD> |
| 3 | + <META NAME="GENERATOR" CONTENT="Adobe PageMill 3.0 Mac"> |
| 4 | + <TITLE>Creating CGI scripts with MacPython</TITLE> |
| 5 | +</HEAD> |
| 6 | +<BODY> |
| 7 | + |
| 8 | +<H3>Creating CGI scripts with MacPython</H3> |
| 9 | +<BLOCKQUOTE> |
| 10 | +Note: this document is work-in-progress, and not tested. |
| 11 | +</BLOCKQUOTE> |
| 12 | + |
| 13 | +<P>MacPython allows you to use Python as a CGI scripting language |
| 14 | +for your webserver. Moreover, there are some helper applications |
| 15 | +that allow you to write your CGI scripts in the same way as for |
| 16 | +Unix and Windows, i.e. obtaining their arguments from <TT>os.environ</TT> |
| 17 | +and sending their results to <TT>stdout</TT>. MacPython also has |
| 18 | +all the facilities to program CGI scripts in the Macintosh way, |
| 19 | +through AppleEvents, but that falls outside the scope of this |
| 20 | +document (reading the source code for the helper scripts will |
| 21 | +give you an idea about how to do this).</P> |
| 22 | + |
| 23 | +<P>For the purpose of this document we will assume you are using |
| 24 | +Apple's Personal Webserver 1.5, which comes standard with your |
| 25 | +machine as of MacOS 9.</P> |
| 26 | + |
| 27 | +<P>The first step is to start the webserver, you will find it |
| 28 | +in your control panels. Give it a folder to serve documents from, |
| 29 | +and check that it is working by pointing your browser at it.</P> |
| 30 | + |
| 31 | +<P>The next step is to tell the webserver that documents with |
| 32 | +a ".<TT>py</TT>" extension should be served through |
| 33 | +the <TT>PythonCGISlave</TT> helper application. Open the webserver, |
| 34 | +choose Preferences, tab Action, Add, Start on Extension, extension |
| 35 | +".py", select application <TT>PythonCGISlave</TT> (which |
| 36 | +lives in <TT>Python:Mac:Tools:CGI</TT>).</P> |
| 37 | + |
| 38 | +<P>The last step is to try it. Put the following script in <TT>Macintosh |
| 39 | +HD:Webpages:hello.py </TT>(assuming your webserver has the default |
| 40 | +settings for its document folder):</P> |
| 41 | + |
| 42 | +<BLOCKQUOTE> |
| 43 | + <P><CODE>print "Content-type: text/plain"<BR> |
| 44 | + print<BR> |
| 45 | + print "Hello world!"<BR> |
| 46 | + import time<BR> |
| 47 | + print "Local time is", time.ctime(time.time())</CODE></P></BLOCKQUOTE> |
| 48 | + |
| 49 | +<P>Point your webbrowser at <A HREF="http://localhost/hello.py">http://localhost/hello.py</A><CODE> |
| 50 | +</CODE>and check whether it works. |
| 51 | + |
| 52 | +</BODY> |
| 53 | +</HTML> |
0 commit comments