This article focuses on the tutorial on running a Python script in CGI on an IIS server, although the performance of IIS is not ideal ... A friend you need can refer to the following
Because of the access to Python web development, just the simplest CGI way to study, say in Windows configuration Python Web development is really troublesome, Linux under the configuration is very easy, just Microsoft has the technical article "Using Python Scripts With IIS, this article describes two methods, one is to use the ASP engine to run the Python script, this may need to use the ActivePython, of course, ASP technology is outdated, I would like to briefly introduce the CGI module operation mode today.
Write a simple CGI-capable Python script (this article describes the 3.2 version of Python):
Print ("status:200 OK") prints a blank line ("content-type:text/html"), which separates the HTTP header from the body print ("
This allows you to guess that CGI is redirecting the standard output stream to the HTTP output stream for Web page or data transfer.
Of course, this cannot be run directly in IIS, we need to configure it, open the Internet Information Services (IIS) Manager interface, and select handler mappings.
Select Add Module mapping on the right side of the interface that appears next.
IIS7 Adding a module map
Assuming that our Python 3.2 is installed in C:\Python32, you can write to this:
Then click OK and select "Yes" in the dialog box that appears next.
OK, our configuration is complete, restart IIS, and then try the code just now. Some people may complain that writing a Web page with CGI can be cumbersome, such as reporting the following error:
HTTP Error 502.2-bad Gateway
The specified CGI application produces an error behavior because it does not return a complete set of HTTP headers. The head it actually returns is "Traceback (most recent call last): File" E:\projects\test.py ", line 3, in <module> 1/0 Zeropisionerror:pis Ion by Zero ".
In fact, we only need to introduce import CGITB at the very beginning; Cgitb.enable () is all right, just like this:
Import CGITB; Cgitb.enable () print ("status:200 OK") prints ("content-type:text/html") printed a blank line that separates the HTTP header from the body print ("< H1>hello world!
That way, if something goes wrong, the error is exported in a friendly way.
For the processing of forms, you can refer to the Import CGI module (CGI). Fieldstorage), there are a lot of this introduction on the Internet, I will not say much, Enjoy it!
"Recommended"
1. Detailed CGI writing data instance code to text or database
2. What is CGI? Detailed description of Python CGI programming
3. Creating a simple Web page tutorial instance using the CGI module
4. Share an example tutorial on pythoncgi programming
5. Sample code for XML and modern CGI applications
6. The FastCGI process unexpectedly exits resulting in a 500 error