mirror of https://github.com/python/cpython
54 lines
2.1 KiB
HTML
54 lines
2.1 KiB
HTML
<HTML>
|
|
<HEAD>
|
|
<META NAME="GENERATOR" CONTENT="Adobe PageMill 3.0 Mac">
|
|
<TITLE>Creating CGI scripts with MacPython</TITLE>
|
|
</HEAD>
|
|
<BODY>
|
|
|
|
<H3>Creating CGI scripts with MacPython</H3>
|
|
<BLOCKQUOTE>
|
|
Note: this document is work-in-progress, and not tested.
|
|
</BLOCKQUOTE>
|
|
|
|
<P>MacPython allows you to use Python as a CGI scripting language
|
|
for your webserver. Moreover, there are some helper applications
|
|
that allow you to write your CGI scripts in the same way as for
|
|
Unix and Windows, i.e. obtaining their arguments from <TT>os.environ</TT>
|
|
and sending their results to <TT>stdout</TT>. MacPython also has
|
|
all the facilities to program CGI scripts in the Macintosh way,
|
|
through AppleEvents, but that falls outside the scope of this
|
|
document (reading the source code for the helper scripts will
|
|
give you an idea about how to do this).</P>
|
|
|
|
<P>For the purpose of this document we will assume you are using
|
|
Apple's Personal Webserver 1.5, which comes standard with your
|
|
machine as of MacOS 9.</P>
|
|
|
|
<P>The first step is to start the webserver, you will find it
|
|
in your control panels. Give it a folder to serve documents from,
|
|
and check that it is working by pointing your browser at it.</P>
|
|
|
|
<P>The next step is to tell the webserver that documents with
|
|
a ".<TT>py</TT>" extension should be served through
|
|
the <TT>PythonCGISlave</TT> helper application. Open the webserver,
|
|
choose Preferences, tab Action, Add, Start on Extension, extension
|
|
".py", select application <TT>PythonCGISlave</TT> (which
|
|
lives in <TT>Python:Mac:Tools:CGI</TT>).</P>
|
|
|
|
<P>The last step is to try it. Put the following script in <TT>Macintosh
|
|
HD:Webpages:hello.py </TT>(assuming your webserver has the default
|
|
settings for its document folder):</P>
|
|
|
|
<BLOCKQUOTE>
|
|
<P><CODE>print "Content-type: text/plain"<BR>
|
|
print<BR>
|
|
print "Hello world!"<BR>
|
|
import time<BR>
|
|
print "Local time is", time.ctime(time.time())</CODE></P></BLOCKQUOTE>
|
|
|
|
<P>Point your webbrowser at <A HREF="http://localhost/hello.py">http://localhost/hello.py</A><CODE>
|
|
</CODE>and check whether it works.
|
|
|
|
</BODY>
|
|
</HTML>
|