blob: 3dc5dc034c9a6bfeffb59596c4df78939c54f7eb [file] [log] [blame]
Jack Jansenab0280d2000-08-25 22:36:13 +00001<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>
10Note: 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
14for your webserver. Moreover, there are some helper applications
15that allow you to write your CGI scripts in the same way as for
16Unix and Windows, i.e. obtaining their arguments from <TT>os.environ</TT>
17and sending their results to <TT>stdout</TT>. MacPython also has
18all the facilities to program CGI scripts in the Macintosh way,
19through AppleEvents, but that falls outside the scope of this
20document (reading the source code for the helper scripts will
21give you an idea about how to do this).</P>
22
23<P>For the purpose of this document we will assume you are using
24Apple's Personal Webserver 1.5, which comes standard with your
25machine as of MacOS 9.</P>
26
27<P>The first step is to start the webserver, you will find it
28in your control panels. Give it a folder to serve documents from,
29and 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
32a &quot;.<TT>py</TT>&quot; extension should be served through
33the <TT>PythonCGISlave</TT> helper application. Open the webserver,
34choose Preferences, tab Action, Add, Start on Extension, extension
35&quot;.py&quot;, select application <TT>PythonCGISlave</TT> (which
36lives 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
39HD:Webpages:hello.py </TT>(assuming your webserver has the default
40settings for its document folder):</P>
41
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>
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>