This commit was manufactured by cvs2svn to create tag 'r23b1-mac'.
[python/dscho.git] / Mac / Tools / CGI / cgi.html
blob3dc5dc034c9a6bfeffb59596c4df78939c54f7eb
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>
8 <H3>Creating CGI scripts with MacPython</H3>
9 <BLOCKQUOTE>
10 Note: this document is work-in-progress, and not tested.
11 </BLOCKQUOTE>
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>
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>
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>
31 <P>The next step is to tell the webserver that documents with
32 a &quot;.<TT>py</TT>&quot; 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 &quot;.py&quot;, select application <TT>PythonCGISlave</TT> (which
36 lives in <TT>Python:Mac:Tools:CGI</TT>).</P>
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>
42 <BLOCKQUOTE>
43 <P><CODE>print &quot;Content-type: text/plain&quot;<BR>
44 print<BR>
45 print &quot;Hello world!&quot;<BR>
46 import time<BR>
47 print &quot;Local time is&quot;, time.ctime(time.time())</CODE></P></BLOCKQUOTE>
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.
52 </BODY>
53 </HTML>