summaryrefslogtreecommitdiff
path: root/docs/modpython.txt
diff options
context:
space:
mode:
Diffstat (limited to 'docs/modpython.txt')
-rw-r--r--docs/modpython.txt73
1 files changed, 66 insertions, 7 deletions
diff --git a/docs/modpython.txt b/docs/modpython.txt
index 5177abf728..388a6168f3 100644
--- a/docs/modpython.txt
+++ b/docs/modpython.txt
@@ -13,14 +13,15 @@ other server arrangements.
Django requires Apache 2.x and mod_python 3.x, and you should use Apache's
`prefork MPM`_, as opposed to the `worker MPM`_.
-You may also be interested in `How to use Django with FastCGI`_.
+You may also be interested in `How to use Django with FastCGI, SCGI or AJP`_
+(which also covers SCGI and AJP).
.. _Apache: http://httpd.apache.org/
.. _mod_python: http://www.modpython.org/
.. _mod_perl: http://perl.apache.org/
.. _prefork MPM: http://httpd.apache.org/docs/2.2/mod/prefork.html
.. _worker MPM: http://httpd.apache.org/docs/2.2/mod/worker.html
-.. _How to use Django with FastCGI: http://www.djangoproject.com/documentation/fastcgi/
+.. _How to use Django with FastCGI, SCGI or AJP: ../fastcgi/
Basic configuration
===================
@@ -37,7 +38,8 @@ Then edit your ``httpd.conf`` file and add the following::
PythonDebug On
</Location>
-...and replace ``mysite.settings`` with the Python path to your settings file.
+...and replace ``mysite.settings`` with the Python import path to your Django
+project's settings file.
This tells Apache: "Use mod_python for any URL at or under '/mysite/', using the
Django mod_python handler." It passes the value of ``DJANGO_SETTINGS_MODULE``
@@ -49,9 +51,29 @@ whereas ``<Location>`` points at places in the URL structure of a Web site.
``<Directory>`` would be meaningless here.
Also, if you've manually altered your ``PYTHONPATH`` to put your Django project
-on it, you'll need to tell mod_python::
+on it, you'll need to tell mod_python:
- PythonPath "['/path/to/project'] + sys.path"
+.. parsed-literal::
+
+ <Location "/mysite/">
+ SetHandler python-program
+ PythonHandler django.core.handlers.modpython
+ SetEnv DJANGO_SETTINGS_MODULE mysite.settings
+ PythonDebug On
+ **PythonPath "['/path/to/project'] + sys.path"**
+ </Location>
+
+.. caution::
+
+ If you're using Windows, remember that the path will contain backslashes.
+ This string is passed through Python's string parser twice, so you need to
+ escape each backslash **twice**::
+
+ PythonPath "['c:\\\\path\\\\to\\\\project'] + sys.path"
+
+ Or, use raw strings::
+
+ PythonPath "[r'c:\\path\\to\\project'] + sys.path"
You can also add directives such as ``PythonAutoReload Off`` for performance.
See the `mod_python documentation`_ for a full list of options.
@@ -146,7 +168,7 @@ If, however, you have no option but to serve media files on the same Apache
``VirtualHost`` as Django, here's how you can turn off mod_python for a
particular part of the site::
- <Location "/media/">
+ <Location "/media">
SetHandler None
</Location>
@@ -163,7 +185,7 @@ the ``media`` subdirectory and any URL that ends with ``.jpg``, ``.gif`` or
SetEnv DJANGO_SETTINGS_MODULE mysite.settings
</Location>
- <Location "media">
+ <Location "/media">
SetHandler None
</Location>
@@ -197,6 +219,41 @@ Here are two recommended approaches:
2. Or, copy the admin media files so that they live within your Apache
document root.
+Using eggs with mod_python
+==========================
+
+If you installed Django from a Python egg_ or are using eggs in your Django
+project, some extra configuration is required. Create an extra file in your
+project (or somewhere else) that contains something like the following::
+
+ import os
+ os.environ['PYTHON_EGG_CACHE'] = '/some/directory'
+
+Here, ``/some/directory`` is a directory that the Apache webserver process can
+write to. It will be used as the location for any unpacking of code the eggs
+need to do.
+
+Then you have to tell mod_python to import this file before doing anything
+else. This is done using the PythonImport_ directive to mod_python. You need
+to ensure that you have specified the ``PythonInterpreter`` directive to
+mod_python as described above__ (you need to do this even if you aren't
+serving multiple installations in this case). Then add the ``PythonImport``
+line inside the ``Location`` or ``VirtualHost`` section. For example::
+
+ PythonInterpreter my_django
+ PythonImport /path/to/my/project/file.py my_django
+
+Note that you can use an absolute path here (or a normal dotted import path),
+as described in the `mod_python manual`_. We use an absolute path in the
+above example because if any Python path modifications are required to access
+your project, they will not have been done at the time the ``PythonImport``
+line is processed.
+
+.. _Egg: http://peak.telecommunity.com/DevCenter/PythonEggs
+.. _PythonImport: http://www.modpython.org/live/current/doc-html/dir-other-pimp.html
+.. _mod_python manual: PythonImport_
+__ `Multiple Django installations on the same Apache`_
+
Error handling
==============
@@ -242,3 +299,5 @@ as necessary.
.. _Expat Causing Apache Crash: http://www.dscpl.com.au/articles/modpython-006.html
.. _mod_python FAQ entry: http://modpython.org/FAQ/faqw.py?req=show&file=faq02.013.htp
.. _Getting mod_python Working: http://www.dscpl.com.au/articles/modpython-001.html
+
+