Home > Uncategorized > Use Python cgi localy on Windows7

Use Python cgi localy on Windows7

February 16, 2012 Leave a comment Go to comments

How to setup python cgi on window 7.

Here’s my first try-out for uing python cgi on my windows7.

1- Create a fake server somewhere on your disk, like D:\myserver

2- Go to your python installation folder and find Lib (for me it’s C:\Python27\Lib). Then copy the file: CGIHTTPServer.py  to the server dir you just created (e.g. D:\myserver).

3- Create a subfolder under myserver: e.g. D:\myserver\cgi-bin.  This will be the folder where you put your codes in.

Copy the python code down the bottom, and save it as test.py. Then put it  into D:\myserver\cgi-binIt  will display “hello world” in your browser.

4-Run the file D:\myserver\CGIHTTPServer.py 🙂 Great,You now have the server running!

5- To run your code: D:\myserver\cgi-bin\test.py. You need to put the server and port into your browser address line, like this:

http://localhost:8000/cgi-bin/test.py

print "Content-Type: text/html"
print
print """<html>
<head><title>First Python HTTP Programming </title></head>
<body>
<h2>Hello World!</h2>
</body>
</html>
"""

By the way, a very nice tutorial: http://lost-theory.org/python/randomimg.html

 

Advertisements
Categories: Uncategorized
  1. hamad
    January 30, 2015 at 5:25 AM

    This is awesome .. THANKS ALOT 🙂 I’m a Python newbie and i know this is gonna help me alot in learning ^_^ THANKS ALOT

  2. leo
    November 21, 2015 at 2:03 PM

    Excellent instruction, very helpful. Thanks a lot 🙂

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: