Here are the steps you should make if you want to use python scripts on IIS 7:
- Please make sure Python is installed properly or refer to Python Notes – 1 : Setup for installation steps.
- Make sure CGI module is installed in IIS 7.
Control Panel -> Programs -> Program and Features -> Turn Windows features on and off -> Internet Information Services -> World Wide Web Services -> Application Development Features -> CGI module (Ensure that it is selected).
- Add web application for Python, In IIS Manager, right click Sites –> Add Web Site..
- In the Add Web Site dialog box, set Site name e.g.: PythonTest, and make it pointing to some folder like C:\PythonTest, then click OK
- In Features View, open Handler Mappings
- On the left pane click Add Script Map ...
- In Request path, put "*.py" as the script files extension, In Executable select "C:\Python25\Python.exe %s %s", or change it according to your Python installation path. (The two "%s" after the executable are required for console-based script interpreters but would not be required for an Internet Server API [ISAPI]-based script interpreter). Then give the script mapping an appropriate Name, like Python. Click OK.
- Create a test.py into the virtual directory (C:\PythonTest), and copy the following script into it.
print 'Status: 200 OK'
print 'Content-type: text/html'
print '<HTML><HEAD><TITLE>Python Sample CGI</TITLE></HEAD>' print '<BODY>'
print '<H1>This is a header</H1>'
print '<p>' #this is a comment
print 'See this is just like most other HTML'
print '<br>'
print '</BODY>'
- Then type http://localhost/pythontest/test.py into your IE URL bar to verify it is working.