Changes between Version 4 and Version 5 of django_apache_and_mod_wsgi
- Timestamp:
- Sep 18, 2007, 4:38:12 PM (17 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
django_apache_and_mod_wsgi
v4 v5 1 1 = How to use django with mod_wsgi = 2 2 3 This is a very simple recipe to deploy a django application with mod_wsgi. This procedure has been tested on Windows but should work on any operating system su rported by apache, mod_wsgi, and django.3 This is a very simple recipe to deploy a django application with mod_wsgi. This procedure has been tested on Windows but should work on any operating system supported by apache, mod_wsgi, and django. 4 4 5 5 == Installation == … … 12 12 In this section I will take you trough an example, the django application is called dj_survey. This application is part of a project called "dj_project". 13 13 14 The urls.pyI used to serve the application with the Django built-in development server:14 The {{{urls.py}}} I used to serve the application with the Django built-in development server: 15 15 {{{ 16 #!python 16 17 from django.conf.urls.defaults import * 17 18 from django.contrib import databrowse … … 33 34 }}} 34 35 35 In httpd.conf you should load the mod_wsgi and include the file containing the configuration of your django application. The trap there is all the path should use "/" and not "\". 36 httpd.conf 36 In {{{httpd.conf}}} you should load the mod_wsgi and include the file containing the configuration of your django application. The trap there is all the path should use "/" and not "\". 37 38 === httpd.conf === 37 39 {{{ 38 40 #This should be included somewhere at the top of this file … … 43 45 }}} 44 46 45 This suppose that you have created a folder named apachein your django project in this folder your should add the following files:47 This suppose that you have created a folder named {{{apache}}} in your django project in this folder your should add the following files: 46 48 47 * 08/16/2007 04:12 PM 1,082 apache_django_wsgi.conf 48 * 08/16/2007 04:31 PM 557 dj_survey.wsgi 49 * 08/16/2007 04:31 PM 4,362 settings_production.py 50 * 08/16/2007 04:09 PM 712 urls_production.py 51 * 08/16/2007 04:33 PM 0 !__init!__.py 49 {{{ 50 08/16/2007 04:12 PM 1,082 apache_django_wsgi.conf 51 08/16/2007 04:31 PM 557 dj_survey.wsgi 52 08/16/2007 04:31 PM 4,362 settings_production.py 53 08/16/2007 04:09 PM 712 urls_production.py 54 08/16/2007 04:33 PM 0 __init__.py 55 }}} 52 56 53 __Note__: There is a file called "!__init!__.py" in <PATH TO YOUR DJANGO PROJECT>/apache. In this case <PATH TO YOUR DJANGO PROJECT> is equal to c:\<LONG PATH>\workspace\dj_project57 __Note__: There is a file called {{{__init__.py}}} in {{{<PATH TO YOUR DJANGO PROJECT>/apache}}}. In this case {{{<PATH TO YOUR DJANGO PROJECT>}}} is equal to {{{c:\<LONG PATH>\workspace\dj_project}}} 54 58 55 Like in the httpd.conf you should pay attention to the separator. You should use "/" and not "\" 56 apache_django_wsgi.conf 59 Like in the {{{httpd.conf}}} you should pay attention to the separator. You should use "/" and not "\" 60 61 === apache_django_wsgi.conf === 57 62 {{{ 58 63 Alias /site_media/ "<PATH TO YOUR DJANGO PROJECT>/media/" … … 89 94 90 95 Now here it is the core of the wsgi application. The path there should use "\\"as separator. 91 dj_survey.wsgi 96 97 === dj_survey.wsgi === 92 98 {{{ 99 #!python 93 100 import os, sys 94 101 … … 108 115 }}} 109 116 110 __Note__: If you need to write something in "error.log" located in the following folder "<Your Apache Installation>\Apache2.2\logs" you can insert the line below in your WSGI file. In our example this file is called "dj_survey.wsgi". This method is very convenient to get the PYTHONPATH correct:117 __Note__: If you need to write something in {{{error.log}}} located in the following folder {{{<Your Apache Installation>\Apache2.2\logs}}} you can insert the line below in your WSGI file. In our example this file is called {{{dj_survey.wsgi}}}. This method is very convenient to get the PYTHONPATH correct: 111 118 {{{ 119 #!python 112 120 print >> sys.stderr, sys.path 113 121 }}} 114 122 115 In this file you are defining the settings t aht will be used by your Django application, in our example this file is called: "dj_project.apache.settings_production"(__Note__: ".py" is implicit and should not be added).116 There is nothing special in that file except that I am pointing to a special ulrs.pywhich reflect the configuration I am using in production.123 In this file you are defining the settings that will be used by your Django application, in our example this file is called: {{{dj_project.apache.settings_production}}} (__Note__: ".py" is implicit and should not be added). 124 There is nothing special in that file except that I am pointing to a special {{{urls.py}}} which reflect the configuration I am using in production. 117 125 118 126 {{{ 127 #!python 119 128 ROOT_URLCONF = 'dj_project.apache.urls_production' 120 129 }}} 121 130 122 urls_production.py 131 === urls_production.py === 123 132 {{{ 133 #!python 124 134 from django.conf.urls.defaults import * 125 135 from django.contrib import databrowse … … 140 150 141 151 == Test == 142 Re tstart apache and now you should be able enjoy your application serve by Apache and mod_wsgi.152 Restart apache and now you should be able enjoy your application serve by Apache and mod_wsgi. 143 153 144 154 == References == … … 146 156 * http://code.google.com/p/modwsgi/ 147 157 * http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango 148 149