title: How do I set up a Python CGI server?
body: <p>I'm running Python 3.2 on Windows. I want to run a simple CGI server on my machine for testing purposes. Here's what I've done so far:</p>
  
  <p>I created a python program with the following code:</p>
  
  <pre><code>import http.server
  import socketserver
  PORT = 8000
  Handler = http.server.CGIHTTPRequestHandler
  httpd = socketserver.TCPServer(("", PORT), Handler)
  httpd.serve_forever()
  </code></pre>
  
  <p>In the same folder, I created "index.html", a simple HTML file. I then ran the program and went to <a href="http://localhost:8000/" rel="nofollow">http://localhost:8000/</a> in my web browser, and the page displayed successfully. Next I made a file called "hello.py" in the same directory, with the following code:</p>
  
  <pre><code>import cgi
  import cgitb
  cgitb.enable()
  print("Content-Type: text/html;charset=utf-8")
  print()
  print("""&lt;html&gt;&lt;body&gt;&lt;p&gt;Hello World!&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;""")
  </code></pre>
  
  <p>Now if I go to <a href="http://localhost:8000/hello.py" rel="nofollow">http://localhost:8000/hello.py</a>, my web browser displays the full code above instead of just "Hello World!". How do I make python execute the CGI code before serving it?</p>