Deploy Django using Apache

Source: Internet
Author: User

1. Environment: Windows 7

2. Version: Python 2.7.8

Django 1.6.5

Apache 2.2 http://httpd.apache.org/(under download-binaries-win32)

Mod_wsgi.so http://www.lfd.uci.edu /~ Gohlke/pythonlibs/# mod_wsgi

3. Download and install python, Django, and Apache

Note: 1. Please install all 32-bit versions, because Apache does not officially have a 64-bit version, and you do not want to find a 64-bit version, because I have found it, it is basically useless ~~

2. after installing Apache, open httpd In the conf directory. in the conf file, change Listen 80 (depending on the Situation). Here I will change it to listen 8088, and then cancel # Before servername, and change the same port to 8088. Open the DOS interface in the bin directory, run httpd-K install, and then you can run Apache.

4. install mod_wsgi.so, place mod_wsgi.so (the name cannot be changed) to the modules directory of apache2.2, and open httpd. CONF file, find the template to load, add the following content, and restart Apache to check whether the template is successful.

Loadmodule wsgi_module modules/mod_wsgi.so

5. Create a project. My project is created in D: \ djangopro. The dos interface is opened here, where Django-Admin startmyproject mysite (all .pyfiles are opened using python.exe ),

Then the Directory D: \ djangopro \ mysite \ is generated. There is a mysite and manage. py under mysite (it is said that this is not the case for old versions)

6. add content in view. py and configure it in URLs. py.

Def Hello (request ):

Return httpresponse ("Hello World ")

Urlpatterns = patterns ('', ('^ Hello/$', hello ),)

7. Find directory in httpd. conf and add the following content:

Wsgiscriptalias/"D:/djangopro/mysite/Django. wsgi"

<Directory "D:/djangopro/mysite">

Order deny, allow
Allow from all
</Directory>

8. Go back to the project file and create Django. wsgi.

Import OS

Import sys

Import Django. Core. Handlers. wsgi

SYS. Path. append (r 'd:/djangopro/mysite ')
OS. Environ ['django _ settings_module '] = 'mysite. setting'
Application = Django. Core. Handlers. wsgi. wsgihandler ()

9. Restart Apache to test whether it is successful.

 

Perception: There are really few Python materials, and there are so few errors. I 've been trying this over the past two days. I really want to swear by myself ~~

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.