Oh! Hands-on with you running Python on IIS

Source: Internet
Author: User

The company's website gave me a headache. In many senior masters of the lead, a large number of CMD in the site to run well, hacker attacks also good, only the site and I do not well, I am tired, the site is fast hanging ...


In order to solve this problem, I think of Python to solve. But how to run Python on the website. I found a lot of information on the Internet. As a result, the problem of copying from one to the other is endless--all kinds of problems appear before my eyes. As I kept on messing around and the manager was constantly watching me go crazy, I finally hit the answer. In fact, the answer is simple, like window paper. Remember when my father was a child, they have a children's song "Wash feet water boil wax gourd feet mud mixed tofu wipe the bottom of paper paste windows."


All right, let's do it!


Uh...


First, we have to go to the official website to download the native Python 2.7. Why use 2.7, not 3. X. The reason is 2.7 compared to the public. Moreover, a lot of development programs are based on this. And 2.7 is about the same as 3.X. Oh...... Actually, I want to use it to compile QT ...


We first officer net to download, website: https://www.python.org/.

Here, we download 2.7.8.





After downloading, we will double-click it. For installation.



I have chosen it all for the sake of convenience. You can choose according to your own Italian music.



Installation



When the installation is complete, we will open IIS. Here, because I use WIN7, so with other systems, you are free. In fact, basically the same. So, you don't have to worry too much. You use is Win2003, I use is Win2008, that swollen do-in fact, there is no problem. Everyone is the same. Look alike. Well, except Linux and Unix. I'm going to introduce it on Windows.


In IIS, we choose to directory (my directory is called Yang-notebook, everyone should know my last name.) )。



After that, we go to the "ISAPI and CGI restrictions" on the side window (in fact, devolution).



Let's start tricks in this "ISAPI and CGI Restrictions"--click "Add".



Fill in the following way (the "path" address here is in accordance with your own situation, do not say, you cheat me.) Lao Zhen Dong Dan Earthquake Xidan, the Cultural Revolution of Pathbreaker, you dare to deceive me, I will use the Red Skull to extinguish you.

Added on the following%s%s. Specific reason, I did not think. Anyway, we all add, I will add, hahaha ...



Click "OK", we look at the results, good!



After clicking OK, we are going to enter the following options. Here, click on "Handler mappings" as shown on my diagram.



When we get in, we click "Add Module Map" on the side to add.



Or, as I said above, selectively copy the following (note that the "path" is to be filled out according to your actual situation, the following "%s%s" must be written).



Next, we click "OK", will pop up a hint frame, here everybody don't panic, click "Yes" to become!



OK, let me see if the bottom list has the "Python" we just built!



All right. Prepare the feature to complete. IIS has already been able to support Python's operation directly! So, now let's start writing code. Writing code is also required. For example, the following code:

#!/usr/bin/env pythonimport cgiprint "content-type:text/html\n" print "Hello world!!!"

I saved it as "show.py" and put it to the root of the website, and then called to see the result:



Good, this is called "Hello World".


Here, be aware that:

Import CGI # This is the package file that must be written. We can see that, in fact, the CGI is the first class to go.

Print "content-type:text/html\n"# This also must be written. It's like this is a CGI request. Because I don't know much, so I can't talk nonsense.


If you do not write print "content-type:text/html\n", the following results will appear:



I heard that a lot of people have this problem, do not know that we solve No.


Well, this is how IIS runs the Python program. All the introductions are done!




Oh! Hands-on with you running Python on IIS

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.