Deploying Django to Apache Web Server in Windows 7

Source: Internet
Author: User
Tags apache log in python

In essence, Django is simply a set of class libraries written in Python. Using Django to develop a site is to use these libraries to write Python code. So the key to learning Django is to learn how to program Python and understand how the Django class library works.

If you have Python development experience, there should be no problems in the learning process, and basically, Django code doesn't use some black magic (such as spoofing in code, some implementation is difficult to interpret or understand). For you, learning Django is about learning her naming conventions and APIs.

Configuration ideas

1, configure the Apache httpd.conf file

2. Configure Django Related configuration files

Configuration process

In fact, the configuration is effective for different environments have different details to deal with, online solutions (including this article) are not necessarily common, but in some circumstances, but the overall idea is to configure the above mentioned two configuration files.

The two common ways to deploy Django projects are to use the Mod_python and Mod_wsgi two deployment methods, where I use Mod_wsgi.

1, first go to the Internet to download a thing called this: mod_wsgi-3.4.ap22.win32-py2.7, there is a file is mod_wsgi.so, and then the copy to the Apache installation directory modules file (the default installation directory is: C: Program Files (x86) Apache Software foundationapache2.2modules)

The following two configurations involve paths that are easily mistaken, and if they are absolute paths, check to see if they are correct.

2. New two files in the Django project directory:

DJANGO.WSGI:

#coding =utf-8

Import OS

Import Sys

Import Django.core.handlers.wsgi

os.environ[' django_settings_module '] = ' appops.settings '

app_apth = "D:/opsapp/appops"

Sys.path.append (app_apth)

application = Django.core.handlers.wsgi.WSGIHandler ()

Apache_django_wsgi.conf:

#Alias/d:/opsapp/appops

Alias/favicon.jpg d:/opsapp/appops/static/images/favicon.jpg

#WSGIScriptAlias/api "d:/opsapp/appops/appapi/handler.py" #注意, here in httpd.conf written words here will not have to write.

Wsgiscriptalias/"D:/opsapp/django.wsgi"

Wsgipassauthorization on

<directory "D:/opsapp/appops/appops" >

Order Deny,allow

Allow from all

</Directory>

alias/static/d:/opsapp/appops/static/

<directory d:/opsapp/appops/static/>

Order Deny,allow

Allow from all

Indexoptions fancyindexing

</Directory>

<directory d:/opsapp/appops/>

Order Deny,allow

Allow from all

Indexoptions fancyindexing

</Directory>

<directory "D:/opsapp" >

Allow from all

</Directory>

The directory structure is as follows:

3, edit Apache configuration file httpd.conf (c:program files (x86) Apache Software foundationapache2.2confhttpd.conf)

Add a sentence in the middle:

LoadModule Wsgi_module modules/mod_wsgi.so

The following configuration is added to the end of the file:

Alias/static d:/opsapp/appops/static #这是为了可以通过url来访问static文件

<location "/static/" >

SetHandler None

</Location><br>

<virtualhost *:80> #配置虚拟目录

ServerName app.ops.test.com

#ServerName 192.168.18.74

DocumentRoot D:/opsapp

Wsgiscriptalias/d:/opsapp/django.wsgi

<directory/>

Order Deny,allow

Allow from all

</Directory>

<Directory/apache>

Allow from all

</Directory>

</VirtualHost>

<directory "d:/opsapp/appops/static/" > #这个一定需要, or Web page style error, CSS does not work

Order Deny,allow

Allow from all

</Directory>

Restarting the Apache service is basically OK.

Common errors

Errors in the access failure are recorded in the Apache log (C:Program Files (x86) Apache Software foundationapache2.2logs),

1, static resources can not access, such as CSS style confusion, need to add in the httpd.conf file configuration:

<directory d:/opsapp/appops/static/>

Order Deny,allow

Allow from all

Indexoptions fancyindexing

</Directory>

2, the emergence of the failure to find modules, such as no module named XXX, there are two main reasons:

1), the path is wrong

2), file naming conflicts with Django or Python internal modules

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.