Install and configure Python web development environment in Windows

Source: Internet
Author: User
Tags install django

This article takes Windows XP/Windows 2003 as an example to introduce the installation and configuration of the Python web development environment in Windows:
1. install Apache
Download the Win32 version of the Apache MSI program to install directly, I use the version is: apache_2.2.9-win32-x86-no_ssl-r2.msi,: Fuse. Download the package and install it directly.
2. Install Python
Download the Win32 version of The activepython MSI program can be directly installed, I use Python 2.5 version, the installation process please refer to: http://www.shuihan.com/article/410.htm
3. Install mod_python
Mod_python is a module in Apache that supports Python CGI. You can directly download the Win32 installation program and install it. I use Apache mod_python 3.3.1. The installer finds the installation directory of Python and adds the directory mod_python under lib/Site-packagesib of Python.
Apache mod_python 3.3.1: mod_python-3.3.1.win32-py2.5-Apache2.2.exe
During the installation process, you can find the installation directory of apache2.2 and select the directory where you just installed Apache.
4. Install the database driver
If the web program needs to access the database, the corresponding database driver must be installed. . The installer adds the directory mysqldb under lib/Site-packagesib in Python.
5. Configure Apache
Add a line to the Apache configuration file (CONF/httpd. conf file under the Apache installation directory) to load mod_python:
Loadmodule python_module libexec/mod_python.so. The configuration file is in the Apache installation directory:
Apache Group/apache2_2/CONF/httpd. conf
6. Test
(1) Add directory configuration under the DocumentRoot directory of Apache. DocumentRoot is usually the Apache Group/apache2/htdocs under the Apache installation directory. The following is my Configuration:

<Directory c:/program files/Apache Group/apache2/htdocs/testpython>
Addhandler mod_python py
Pythonhandler testmyfirstpage. py
Pythondebug on
</Directory>

(2) Compile testmyfirstpage. py and save it under testpython. The Code is as follows:

From mod_python import Apache
Def handler (req ):
Req. Write ("Hello world! ")
Return Apache. OK

(3) enter the address http: // 127.0.0.1/testpython/testmyfirstpage. py in the browser and you will see hello World! .
7. All right! The installation is complete!

==========================================

Install and configure python in WindowsAuthor: Cold Water Date: font size: Small Medium big one, installation:
1. Download and install: Download http://python.org/download/download the Windows version (the latest version is python2.5.2, click here to download). After the download is complete, double-click it and install it step by step. (There is no need to participate in the next step. At most, you need to change the installation target path when installing it yourself, so I won't be arrogant here, but the texture is omitted)
2. test whether the installation is successful: After installation, start-> Program-> Python 2.5-> Start Python command line and input: Print "Hello world". If "Hello world" is output ", it indicates that the installation is successful.
3. add environment variables: Right-click "my computer"> "properties"> "advanced"> "environment variables" and enter your python installation location in path, it is much simpler than Java. For example, if my ID is D:/python25133, it should be the parent-level directory of pythonw.exe.
4. programming test: Create a folder, for example, create a text file under D:/myprogram/Python/and rename it hello. PY, open the text in notepad and enter: Print "Hello World"

Enter Python hello in the D:/myprogram/Python/path at the command prompt. py. If the environment variable is set in step 1 above, enter Hello directly. PY (environment variables must be set), the program will output Hello world.
5. Let's look at another slightly complicated program: integer1 = raw_input ("Enter the first INTEGER:/N ")
Integer1 = int (integer1)
Integer2 = raw_input ("enter the second INTEGER:/N ")
Integer2 = int (integer2)
Sum = integer1 + integer2
Print "the sum is", Sum

Save the preceding content as sum. py.
(Note: raw_input is a built-in function that requires user input. Integer1 = int (integer1) converts integer1 to an integer .)
The execution result is:E:/> Python E:/Python/SUM. py
Enter the first INTEGER:
8
Enter the second INTEGER:
11
The sum is 19

============================================================ WINXP + install and configure Apache + MySQL + Python + Django

It took a day to complete the installation of Apache + MySQL + Python + Django in WINXP. The procedure is as follows:
1. Software Download
1,
Http://www.apache.org/dist/httpd/modpython/win/3.3.1/
Download mod_python-3.3.1.win32-py2.5-apache2.2.exe
2,
Http://www.python.org/download/releases/2.5.4/
Download python-2.5.4.msi
3,
Http://www.djangoproject.com/download/
Download django-1.0.2-final.tar.gz
4,
Http://sourceforge.net/projects/mysql-python/
Download mysql-python-1.2.2.win32-py2.5.exe
Ii. Installation
1. Install python2.5
2, install mod_python-3.3
3. Install Django-1.0
Decompress django-1.0.2-final.tar.gz to the python installation directory (E:/python25/Django in this example), run the command line to E:/python25, and run "Python Django/setup. PY install ", Django is installed under E:/python25/lib/Site-packages/Django (E:/python25/Django can be deleted ).

Note:

Django mainly uses the django-admin.py script to manage the project, by default, Django is installed in the python installation directory, generally is: in the $ Python/lib/Site-packages/Django directory, we need to enter a long address to call the django-admin.py: "E: /program files/Python/lib/Site-packages/Django/bin/django-admin.py "to call, in order to facilitate the call of the django-admin.py, we add the directory where the django-admin.py is located to the path of the system, so that the management script can be called directly using the django-admin.py at the command prompt without entering a long address.
4, install MySQL-python-1.2
(Make Python support MySQL database)
3. Configuration
1. Create a project
Run the command line to enter E:/python25/lib/Site-packages/Django/bin, run the django-admin.py startproject myproj, and create a project named myproj.
2. Create a py file
Create hello. py in the E:/python25/lib/Site-packages/Django/bin/myproj directory:
From Django. Http import httpresponse
Def index (request ):
Return httpresponse ('hello, Django! So hard *_*')
3. Configure httpd. conf of Apache
Add loadmodule python_module modules/mod_python.so
Add
<Location "/">
Sethandler Python-Program
Pythonpath "['e:/python25/lib/Site-packages/Django/bin'] + SYS. path"
Pythonhandler Django. Core. Handlers. modpython
Setenv django_settings_module myproj. Settings
Pythoninterpreter inves
Pythondebug off
</Location>
4. Modify the URLs. py file.
Modify URLs. py in the directory e:/python25/lib/Site-packages/Django/bin/myproj:
From Django. conf. URLs. defaults import *
Urlpatterns = patterns ('',
(R '^ $', 'myproj. Hello. Index '),
)
4. Run
Restart the apache service and access http: // localhost/to view the following information:
Hello, Django! So hard *_*
5. Reference Links
1, http://hi.baidu.com/beloving/blog/item/32f65e60ab7c29de8cb10df9.html
Http://hideto.javaeye.com/blog/42538 2
3, http://loamy.javaeye.com/blog/237161

Copyright Disclaimer: During reprinting, please use hyperlinks to indicate the original source and author information of the article and this statement
Http://lily64.blogbus.com/logs/34226333.html

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.