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

Sheila King usenet at thinkspot.net
Sat Jun 1 18:23:27 CEST 2002


On Sat, 1 Jun 2002 18:16:28 +1000, "Ken" <ken at hotmail.com> wrote in
comp.lang.python in article <ad9vo8$utftp$1 at ID-49758.news.dfncis.de>:
 
> Yes, I want to display the content of another html file (main.html in this
> example) onto the browser. How do I do that? And also, how do I set target
> to which frame to display?

If you are trying to open some file and output it to the browser, then:

f = open('main.html', 'r')
myhtml = f.read()
f.close()
print myhtml

Depending on what else the script has already done. For example, if you are
printing the HTML output, instead of redirecting, you do need to print the
Content-type before printing the contents of main.html:

print "Content-type: text/html\n"

But, if you are redirecting to another URL instead, then omit the line show
above and print this line:

print "Location: http://replacement-url\n"


--
Sheila King
http://www.thinkspot.net/sheila/
http://www.k12groups.org/






More information about the Python-list mailing list