I am running Python 3.2 on Windows. I want to run a simple CGI server on my machine for testing. Here is what I have done so far:
I created a python program with the following code:
import http.server
import socketserver
PORT = 8000
Handler = http.server.CGIHTTPRequestHandler
httpd = socketserver.TCPServer(("", PORT), Handler)
httpd.serve_forever()
In the same folder, I created "index.html", a simple HTML file. Then I ran the program and went to http: // localhost: 8000 / in my web browser, and the page was successfully displayed. Then I made a file called "hello.py" in the same directory with the following code:
import cgi
import cgitb
cgitb.enable()
print("Content-Type: text/html;charset=utf-8")
print()
print("""<html><body><p>Hello World!</p></body></html>""")
Now, if I go to http: // localhost: 8000 / hello.py , my web browser will display the full code above, and not just "Hello World!". How to get python to execute CGI code before serving it?