[Tutor] CGI File Woes
Alan Gauld
alan.gauld at btinternet.com
Sun Sep 30 10:02:48 CEST 2007
"wormwood_3" <wormwood_3 at yahoo.com> wrote
> #!/usr/bin/python2.4
>
> import cgitb; cgitb.enable()
>
> thefile = open("template.html", "r")
> templatestuff = thefile.read()
> thefile.close()
> print "Content-Type: text/html"
> if templatestuff:
> print "Found it"
> title1 = "I am a title!"
> body1 = "I am some hot content"
> print templatestuff % (title1, body1)
>
> "template.html" is in the same dir, and is simply:
>
> http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
> <html>
> <html>
Did you mean for there to be two <html> tags or is it a typo?
> <head>
> <title> %s </title>
> </head>
> <body>
> %s
> </body>
> </html>
>
> If I run this script without the 3 lines after the import line,
> it works fine (namely I get an error that templatestuff is not
> defined,
> I am getting a 500 Internal Server Error.
> Since I am not shown an error page with cgitb, this would likely
> mean a syntax error.
I've never used gcitb (and until now didn't know it existed!)
so can't comment.
But I usually see this when the web user doesn't have
permission to open the html file. But...
> .... I have confirmed the file has the right permissions,
> I have even tried it with all permissions set on that file.
For all users?
Remember that the web server runs as a separate user
and that's the user than needs to open the file.
HTH,
--
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld
More information about the Tutor
mailing list