[Tutor] .cgi or .py for Python CGIs
P. Alejandro Lopez-Valencia
Tue, 11 Dec 2001 17:43:57 -0500
----- Original Message -----
From: "Remco Gerlich" <email@example.com>
To: "tutor-python.org" <firstname.lastname@example.org>
Sent: Tuesday, December 11, 2001 12:16 PM
Subject: Re: [Tutor] .cgi or .py for Python CGIs
> On 0, Frank Peavy <email@example.com> wrote:
> > I have seen references to various CGI scripts and some have the .cgi
> > extension and some have a .py extension. Which is correct? Is there a
> > preferred method?
> Python doesn't care. It only needs .py when you import modules from
> There *might* be server settings so that it matters, like I can imagine
> on a Windows server the .py is needed to associate it with Python, but on
> Unix server it should never matter, extensions are irrelevant.
> So it's probably a matter of taste.
> Remco Gerlich
Not exactly. As a rule web servers (as contrasted to the operating system
they run on), do use file extensions to identify CGI programs, particularly
if they are not in the CGI root directory (usually cgi-bin) but in some
other place in the web server virtual file system. Always think of a web
server as an independent operating system running within a virtual machine,
that has access to low level system calls (the operating system it runs on).
Namely, using apache as an example:
/cgi-bin (root CGI directory) -> You can have any extension or note, by
definition anything is executable, and therefore the security model implies
that only the administrator has access to this directory.
~/cgi-bin (user home CGI directory) -> By default you need the .cgi
extension to tell the web server the file is an executable. This can change
depending on the server administrator ideas of what he/she considers OK for
a luser, say, he writes his private CGIs with python, thus he adds .py to
the list of allowed CGI extensions (I know I do ;).
/foo/bar (some data directory in the virtual web server filesystem) -> Same
situation as the previous, yet he who allows this kind of file execution
should be given the choice to switch jobs to salesperson in an incense shop.