I am messing around trying to test a CGI Python script locally on a Windows machine..
I followed a tutorial, so it's pretty simple. Here is my Python script (named test_cgi.py, located in a cgi-bin directory).
print "Content-type: text/html"
print "<html>"
print "<title>Test CGI</title>"
print "<body>"
print "<p>Hello World!</p>"
print "</body>"
print "</html>"
Here is another script that will start the server:
import BaseHTTPServer
import CGIHTTPServer
import cgitb; cgitb.enable() ## This line enables CGI error reporting
server = BaseHTTPServer.HTTPServer
handler = CGIHTTPServer.CGIHTTPRequestHandler
server_address = ("", 8000)
handler.cgi_directories = [""]
httpd = server(server_address, handler)
httpd.serve_forever()
After starting the server, when I navigate to http://localhost:8000/test_cgi.py, instead of the browser displaying the HTML contents, it displays the ENTIRE contents of the script. Any ideas?
- Yes, all my files have executable permissions.
- Yes, I also tried executing python -m CGIHTTPServer from command line.. This starts the server successfully, as does my script. :(