Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Detailed steps for setting up a Python Web environment

2025-02-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces "the detailed steps of building the Python Web environment". In the daily operation, I believe that many people have doubts about the detailed steps of building the Python Web environment. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "the detailed steps of building the Python Web environment"! Next, please follow the editor to study!

Installation steps:

Installation Note: mod_python has strict requirements for both apache and python versions, so you need to find the right version when installing. I installed mod_python-3.3.1.win32-py2.***pache2.2, and the corresponding python version is 2.***pache version 2.2.

1. Install python2.5.x

Download it from the python website first. I downloaded version 2.5.4. The installation is basically set by default. There is no need to change.

two。 Install Apache Server

First download the version from the apache website, I downloaded the Apache2.2.14 version, the installation is basically the default all the way, there is a step in the middle is to fill in the domain name, administrator information, just fill in a random one. There is another step to choose whether everyone or only the current user can choose one, which is the difference between the two ports.

After installation, select start-> Apache HTTP Server 2.2 muri-> Control Apache Server-- > Start Apache in Console. Start Apache Server. Then test it in the browser. Http://localhost:8080 (the port varies according to your choice). If everything is all right, there should be the word It Works.

3. Install mod_python

Download mod_python. The installation location of python is automatically detected during installation. However, you need to manually select the location where apache is installed. Choose to go to the apache2 layer (my computer is D:\ Program Files\ Apache Software Foundation\ Apache2.2). Mod_python adds some libraries in the lib directory of python and the mod_ python.so library in the modules directory of Apache.

We need to configure apache in the process of building a simple Python Web environment.

1. Adding mod_pythonmod_python does not automatically modify the configuration file. For apache to know how to parse .py files, you need to do some configuration in apache's httpd.conf file. There is a bunch of LoadModule commands in the httpd.conf file, and we add a line

#

# LoadModule logio_module modules/mod_logio.so

LoadModule log_config_module modules/mod_log_config.so

# LoadModule log_forensic_module modules/

Mod_log_forensic.so

# LoadModule mem_cache_module modules/mod_mem_cache.so

LoadModule mime_module modules/mod_mime.so

# LoadModule mime_magic_module modules/mod_mime_magic.so

LoadModule negotiation_module modules/mod_negotiation.so

# LoadModule proxy_module modules/mod_proxy.so

# LoadModule proxy_ajp_module modules/mod_proxy_ajp.so

# LoadModule proxy_balancer_module modules/

Mod_proxy_balancer.so

# LoadModule proxy_connect_module modules/

Mod_proxy_connect.so

# LoadModule proxy_ftp_module modules/mod_proxy_ftp.so

# LoadModule proxy_http_module modules/mod_proxy_http.so

# LoadModule rewrite_module modules/mod_rewrite.so

LoadModule setenvif_module modules/mod_setenvif.so

# LoadModule speling_module modules/mod_speling.so

# LoadModule ssl_module modules/mod_ssl.so

# LoadModule status_module modules/mod_status.so

# LoadModule substitute_module modules/mod_substitute.so

# LoadModule unique_id_module modules/mod_unique_id.so

# LoadModule userdir_module modules/mod_userdir.so

# LoadModule usertrack_module modules/mod_usertrack.so

# LoadModule version_module modules/mod_version.so

# LoadModule vhost_alias_module modules/mod_vhost_alias.so

LoadModule python_module modules/mod_python.so

The main function of this line is to load the mod_python.so library.

two。 Configure the virtual directory.

Similar to other language configurations for Apache servers. Add a directory block to the Httpd.conf file.

AddHandler mod_python .py

PythonHandler fetchpage

PythonDebug On

Where fetchpage is the .py file name

3. Write a test file. Save it in the / htdocs/test directory with the same file name as in the configuration file above.

From mod_python import apache def handler (req): req.content_type = 'text/plain' req.write ("Hello World!\ n") return apache.OK here, the study of "detailed steps for building a Python Web environment" is over. I hope I can solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report