Code

Changes between Version 4 and Version 5 of django_apache_and_mod_wsgi


Ignore:
Timestamp:
09/18/07 14:38:12 (7 years ago)
Author:
ramiro
Comment:

some wiki formatting fixes

Legend:

Unmodified
Added
Removed
Modified
  • django_apache_and_mod_wsgi

    v4 v5  
    11= How to use django with mod_wsgi = 
    22 
    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 surported by apache, mod_wsgi, and django. 
     3This 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. 
    44 
    55== Installation == 
     
    1212In 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". 
    1313 
    14 The urls.py I used to serve the application with the Django built-in development server: 
     14The {{{urls.py}}} I used to serve the application with the Django built-in development server: 
    1515{{{ 
     16#!python 
    1617from django.conf.urls.defaults import * 
    1718from django.contrib import databrowse 
     
    3334}}} 
    3435 
    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 
     36In {{{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 === 
    3739{{{ 
    3840#This should be included somewhere at the top of this file 
     
    4345}}} 
    4446 
    45 This suppose that you have created a folder named apache in your django project in this folder your should add the following files: 
     47This suppose that you have created a folder named {{{apache}}} in your django project in this folder your should add the following files: 
    4648 
    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{{{ 
     5008/16/2007  04:12 PM             1,082 apache_django_wsgi.conf 
     5108/16/2007  04:31 PM               557 dj_survey.wsgi 
     5208/16/2007  04:31 PM             4,362 settings_production.py 
     5308/16/2007  04:09 PM               712 urls_production.py 
     5408/16/2007  04:33 PM                 0 __init__.py 
     55}}} 
    5256 
    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_project 
     57__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}}} 
    5458 
    55 Like in the httpd.conf you should pay attention to the separator. You should use "/" and not "\" 
    56 apache_django_wsgi.conf 
     59Like in the {{{httpd.conf}}} you should pay attention to the separator. You should use "/" and not "\" 
     60 
     61=== apache_django_wsgi.conf === 
    5762{{{ 
    5863Alias /site_media/ "<PATH TO YOUR DJANGO PROJECT>/media/" 
     
    8994 
    9095Now 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 === 
    9298{{{ 
     99#!python 
    93100import os, sys 
    94101 
     
    108115}}} 
    109116 
    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: 
    111118{{{ 
     119#!python 
    112120print >> sys.stderr, sys.path  
    113121}}} 
    114122 
    115 In this file you are defining the settings taht 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.py which reflect the configuration I am using in production. 
     123In 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). 
     124There 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. 
    117125 
    118126{{{ 
     127#!python 
    119128ROOT_URLCONF = 'dj_project.apache.urls_production' 
    120129}}} 
    121130 
    122 urls_production.py 
     131=== urls_production.py === 
    123132{{{ 
     133#!python 
    124134from django.conf.urls.defaults import * 
    125135from django.contrib import databrowse 
     
    140150 
    141151== Test == 
    142 Retstart apache and now you should be able enjoy your application serve by Apache and mod_wsgi. 
     152Restart apache and now you should be able enjoy your application serve by Apache and mod_wsgi. 
    143153 
    144154== References == 
     
    146156 * http://code.google.com/p/modwsgi/ 
    147157 * http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango 
    148  
    149