Configure Apache model_python in Django

Source: Internet
Author: User
Configure Apache model_python in Django

Www.jz123.cn 2010-09-28 Source:
China site creation Editor (Yuan)
I want to deliver news

1: this problem has occurred for a long time because my Apache model file does not have the mod_python.so file.

Solution: Install Python Django and apance first.

Download the mod_python-3.3.1.win32-py2.5-apache2.2.exe file. During installation, it will automatically find the location of python25 and click Continue.

But in the second to last step, there is an option: select the location where your computer is installed, click the Apache location to confirm, and then he will install the mod_python.so file into the model file:

Add loadmodule pytyhon_module modules/mod_python.so to httpd. conf of Apache.

To configure Django to Apache:

This blog explains how to install Apache and mod_python in Windows. The steps below are verified.

1:
From http://httpd.apache.org/
To obtainApache_2.2.3-win32-x86-no_ssl.msiThis installation file;
Run this MSI to successfully install Apache.

2:

On the Internet, many users can use Apache and mod_python source code to compile and install mod_python. However, if you only want to install it quickly

Http://www.apache.org/dist/httpd/modpython/win/3.2.10/

Direct download

Mod_python-3.2.10.win32-py2.4-apache2.2.exe

File, run this EXE to install mod_python to python2.4 and apache2.2;

Due to GFW blocking, you may not be able to access the Apache website, so you can download it from here:

Http://files.cnblogs.com/zhengyun_ustc/mod_python-3.2.10.win32-py2.4-apache2.2.rar

3:

We use

Python django-admin.py startproject myproject

Command to create a Django project myproject under the Django directory of drive C. We put the referenced image files, CSS files, and other static Resources in the media directory under the myproject folder.

In this case, modify the three parameters in the settings. py file under the myproject directory to change from relative path to absolute path:

Modified configuration line

# Django settings for myproject project.

'''

Change the relative path to the absolute path. Mainly include:

Media_root

Template_dirs

Static_path

'''

# Absolute path to the directory that holds media.

# Example: "/home/Media/media.lawrence.com /"

Media_root = 'C:/Django/myproject'

Static_path = 'C:/Django/myproject/media'

Template_dirs = (

# Put strings here, like "/home/html/django_templates ".

# Always use forward slashes, even on Windows.

'C:/Django/myproject/templates ',

)

Make sure that the three parameters are absolute paths.

4:

Configure the httpd. conf configuration file of Apache:

First, add a line under the configuration of "dynamic shared object (DSO) support"

Loadmodule python_module modules/mod_python.so

This must be manually added.

5:

The parameters required by Apache are listed as follows:

Project name: myporject

The URL to be accessed is http: // localhost: 80/mysite/

Static resource file storage directory: C:/Django/myproject/Media

Project folder path: C:/Django/myproject

Now, you should add this configuration at the end of the httpd. conf file to let Apache know where to locate the myproject/settings. py file:

Added configuration lines

# Mysite directory path: C:/Django/myproject,

# But for pythonpath, it must be set to the upper-level directory of this directory!

# This site URL: http: // localhost: 80/mysite/

<Location "/mysite/">

Sethandler Python-Program

Pythonpath "SYS. Path + ['C:/Django']"

Pythonhandler Django. Core. Handlers. modpython

Setenv django_settings_module myproject. Settings

Pythoninterpreter mysite

Pythondebug on

</Location>

For the above configuration, limodou commented: "The above pythonpath mainly adds the directory of myproject to SYS. path so that Django can find it. Absolute path is required.

The django_settings_module set in setevn corresponds to your project name. configuration file. Therefore, in order to import the project name and configuration file, you need to set the pythonpath above.

We recommend that you set pythondebug and pythonautoreload to off during production ."

To enable images, CSS, and scripts to be successfully loaded by Apache, add the following configuration at the end of httpd. conf:

Added configuration lines

# Alias/site_media is used to set a URL access alias for the static file of myproject.

Alias/site_media C:/Django/myproject/Media

<Location "/site_media/">

Sethandler none

</Location>

 

# Alias/media sets the access alias of a URL for the static Django admin file.

Alias/Medic:/Django-0.95/Django/contrib/admin/Media

<Location "/Media/">

Sethandler none

</Location>

 

# File types we want to serve statically

# Case insensative match

<Locationmatch "(? I) \. (JPG | GIF | PNG | TXT | ICO | PDF | CSS | JPEG) $ ">

Sethandler none

</Locationmatch>

 

In step by step, limodou specifically says, "at the same time, you can note that I changed settings to settings_apache. On the one hand, I will change the content related to the relative path to the absolute path, and on the other hand, I want to keep the current settings. py ." This is also a good practice.

Finally, modify maxrequestsperchild to 1, which is optional. Limodou says this: "If you don't want to restart Apache for testing every time, you can change: maxrequestsperchild 0. To: maxrequestsperchild 1"

 

Restart the apache service.

6:

Browse http: // localhost: 80/mysite.

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.