Setup WSGI Apache for Django 1.4 Production


Here is the example of wsgi under your //wsgi.py:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
"""
WSGI config for bodyslap project.

This module contains the WSGI application used by Django’s development server
and any production WSGI deployments. It should expose a module-level variable
named “application“. Django’s “runserver“ and “runfcgi“ commands discover
this application via the “WSGI_APPLICATION“ setting.

Usually you will have the standard Django WSGI application here, but it also
might make sense to replace the whole Django WSGI application with a custom one
that later delegates to the Django one. For example, you could introduce WSGI
middleware here, or combine a Django application with an application of another
framework.

"""

# Django wsgi for apache
import os
import sys
PROJECT_PATH = os.path.realpath(os.path.dirname(__file__))

# django project absolute path
sys.path.append(os.path.join(PROJECT_PATH, ‘..’))
sys.path.append(os.path.join(PROJECT_PATH))

from settings import DEBUG

if not DEBUG:
    import monitor
    monitor.start(interval=1.0)
    monitor.track(os.path.join(os.path.dirname(__file__), ‘..’))

# django core location
sys.path.append(‘/usr/local/lib/python2.7/dist-packages/django/’)

# Your django settings
os.environ[‘DJANGO_SETTINGS_MODULE’] = ‘bodyslap.settings’

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.