Atitit.python Configuration Attilax Summary of the Web environment

Source: Internet
Author: User

Atitit.python configuration attilax Summary of the Web environment

1 .  download modpython/ 1

1 . 1. installing python2.5.1 1

1 . 2. installing Modpython 1

2 .  to set the URL requestor for a py file 2

3 .  www/py/t.py 2

4 .  access URL http://localhost/py/t.py/handler 2

5 .  Advanced Knowledge 2

5 . 1. native (native) Mod_python processor 2

5 . 2. so What exactly did Mod_python do? 3

6 .  Reference 5

1.Downloadmodpython/

Currently only mod_python-3.3.1.win32-py2.5-apache2.2 is compiled:

2.7 need to compile for themselves ...

http://archive.apache.org/dist/httpd/modpython/

http://archive.apache.org/dist/httpd/modpython/
To find, only python2.5 is compiled well, others need to compile, but in fact , you can change the file python25.dll you want to Python27.dll, Because these versions are basically compatible.

1.1.installing python2.5.1

1.2.installationModpython

D:\wamp\bin\apache\Apache2.2.21\modules\mod_python.so

Modify http.conf

Add LoadModule python_module modules/mod_python.so

2. to set the URL requestor for a py file

Can be set in htt.p. confi file inside

can also be set in the . htaccess file

AddHandler Mod_python. py

SetHandler Mod_python

Pythonhandler Mod_python.publisher

#mod_python. Publisher

Pythondebug on

3.www/py/t.py

From Mod_python import Apache

def handler (req):

Req.content_type = ' Text/plain '

Req.write ("Hello world!")

return Apache. Ok

Author:: Old Wow's paw attilax Ayron, email:[email protected]

Reprint please indicate source: http://www.cnblogs.com/attilax/

4.access URL Http://localhost/py/t.py/handler

Note the URL to access the module in the method.

5.Advanced Knowledge5.1.native (native) Mod_python processor  

<Directory/mywebdir>

AddHandler Mod_python. py

Pythonhandler MyScript

Pythondebug on

</Directory>

From Mod_python import Apache

def handler (req):

Req.content_type = ' Text/plain '

Req.write ("Hello world!")

return Apache. Ok

Access URL is xxxx.py module

5.2.so What exactly did Mod_python do?

Suppose we have the following configuration file:

<Directory/mywebdir>

AddHandler Mod_python. py

Pythonhandler MyScript

Pythondebug on

</Directory>

Note:/mywebdir is a physical absolute path. There is also a Python program '/mywedir/myscript.py ' as follows:

From Mod_python import Apache

def handler (req):

Req.content_type = "Text/plain"

Req.write ("Hello world!")

return Apache. Ok

Explain this procedure:

The addHandler instruction tells Apache that all the. py files in the Mywebdir directory or its subdirectories, any requests for these files are handled with Mod_python, Pythonhandler myscript instructions tell Mod_ Python executes the default processor with MyScript. "Pythondebug on" instructs the Mod_python to print the error message to the client (as opposed to writing the log file) if an error occurs, which is useful in developing this option.

When a request is made, Apache processes the request by calling the processor in Mod_python, Mod_python first checks whether the requested processor is specified in the configuration file (remember, its role is transmitter dispatcher), in our case, mod_ In addition to calling the default processor, Python does not invoke any other processors, and then Mod_python will find "Pythonhandler myscript" instructions and follow the steps below:

1. If you have not done it before, add the directory specified by Pythonhandler to Sys.path.

2. Try to introduce a myscript module (note that if MyScript is in a subdirectory of the Pythonhandler specified directory, the introduction will go wrong because the subdirectory is not added to the Sys.path, and the way to resolve this is to use the package) for example: " Pythonhandler Subdir.myscript "

3. Find a way to name handler in MyScript.

4. Call this method and pass the request object to it.

5. Now let's go into this script to see:

From Mod_python import Apache

This introduction statement provides us with an interface to access Apache. In rare cases, each Mod_python program will have this line in general.

def handler (req):

This is the declaration of the processor method, it is called "handler" because mod_python in the instructions to use the name, converted it to lowercase and remove "python", so "Pythonhandler" became "handler", you can give it a different name, and specify it explicitly by using "::" in the instruction. For example, if the processor method is called "spam", then the instruction should be "Pythonhandler myscript::spam".

Note that the processor must have a parameter

6.Reference

Mod_python Chinese document . htm

apache (Wamp)   add python support   - ei__nino column   -   blog channel   - csdn. net.htm

Configuring the python_ Programming Development _ software tutorial in Apache , Windows platform _ home of the script . htm

Atitit.python Configuration Attilax Summary of the Web environment

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.