How to open a HTML file when the python cgi program is executing?

Sheila King usenet at
Sat Jun 1 03:48:33 EDT 2002

On Sat, 1 Jun 2002 16:43:01 +1000, "Ken" <ken at> wrote in
comp.lang.python in article <ad9q91$vlrsb$1 at>:

> How do I open a HTML file when the cgi program is executing?
> The only method I can think of, which doesn't work is this:
> <meta HTTP-EQUIV="REFRESH" CONTENT="0; URL=main.html">

What do you mean by "open an HTML file when the cgi program is executing"?

Are you talking about displaying the resulting HTML output.

HTML output from a cgi script is simply printed to standard output.

Here is a very simply cgi script (basically "Hello World"):

=============(begin hello script)===============
#!/usr/bin/env python

print "Content-type: text/html\n"
print "<HTML><HEAD><TITLE>Hello, World!</TITLE></HEAD>"
print "<BODY><H1>HELLO, WORLD!!!</H1></BODY></HTML>"

=============(end hello script)===============

Change the interpreter path

#!/usr/bin/env python

as appropriate for your server.

Save the above as something like or hello.cgi
upload it to the cgi-bin on your server. Make sure file permissions are set
for executable (this will probably be 777 or 755 depending on your server
configuation). Make sure you upload it in ASCII/TEXT mode.

Then point your browser to

where you replace with your actual domain name.

This should display an HTML page with the H1 header saying "Hello, World!!"

Sheila King

More information about the Python-list mailing list