getting started with cgi on os x

holger krekel pyth at devel.trillke.net
Mon Nov 11 01:09:40 EST 2002


Stephen Aichele wrote:
> Hello.
> 
> A few years back, I dove into python, and after being away from it
> for a year, I'm looking at using it to build a cgi backend to a
> website.
> 
> I'm new to cgi.  I'm working on a mac running os x.  
> 
> Question #1:  I'm assuming that I need to have a web server up and
> running on my development machine to get cgi pages to display in a
> browser.  Any info on setting up apache or medusa(?) to run python
> cgi scripts on os x would be much appreciated.  I feel a bit lost.

I can't help with this one.  But google turns out 

    http://www.macdevcenter.com/pub/ct/49

which mentions that OSX has a *builtin* Apache web server.

> Question #2: I'm also assuming that the easiest way to call a python
> cgi script from a web page is via a form 'action'.  I'd really like
> to use javascript to call python cgi scripts/methods , (rather than
> using 'action' from a form ).  My hunch is that this is impossible,
> or at least a pain in the rear.  Am I right?

Not quite. Problem is that you can't easily do it in a 
cross-plattform way.  But basically you could do (works on mozilla, 
not very different on IE):

var req;
req = new XMLHttpRequest();

function toserver() {
    req.onload = handle_response;
    req.open('POST', 'http://server.where.i.came.from', true);
    req.send('somevalue-which-will-appear-in-BODY', true)
}

function handle_response() {
    gotback = req.responseXML;
    // process 
}
   
But still  using the form-submit hooks is probably more 
cross-platform and avoids some pitfalls (specifically w/r 
to authentication) with the former approach. 
You do know that you can intercept the submit-process
with javascript?

<form ...>
    <input type="button" name="save" value="save something" 
           onclick="intercept_function();">
</form>

HTH,
    
    holger




More information about the Python-list mailing list