Django

Code

Changeset 5896

Show
Ignore:
Timestamp:
08/15/07 07:25:21 (1 year ago)
Author:
mtredinnick
Message:

Fixed #4296 -- Added more explanation around the PythonPath? directory setting. Based on contributions from a cast of thousands (Simon Greenhill, Paul Bissex, Graham Dumpleton, ...). Thanks, all.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/docs/modpython.txt

    r5668 r5896  
    6363        **PythonPath "['/path/to/project'] + sys.path"** 
    6464    </Location> 
     65 
     66The value you use for ``PythonPath`` should include the parent directories of 
     67all the modules you are going to import in your application. It should also 
     68include the parent directory of the ``DJANGO_SETTINGS_MODULE`` location. This 
     69is exactly the same situation as setting the Python path for interactive 
     70usage. Whenever you try to import something, Python will run through all the 
     71directories in ``sys.path`` in turn, from first to last, and try to import 
     72from each directory until one succeeds. 
     73 
     74An example might make this clearer. Suppose 
     75you have some applications under ``/usr/local/django-apps/`` (for example, 
     76``/usr/local/django-apps/weblog/`` and so forth), your settings file is at 
     77``/var/www/mysite/settings.py`` and you have specified 
     78``DJANGO_SETTINGS_MODULE`` as in the above example. In this case, you would 
     79need to write your ``PythonPath`` directive as:: 
     80 
     81    PythonPath "['/var/production/django-apps/', '/var/www'] + sys.path" 
     82 
     83With this path, ``import weblog`` and ``import mysite.settings`` will all 
     84work. If you had ``import blogroll`` in your code somewhere and ``blogroll`` 
     85lived under the ``weblog/`` directory, you would *also* need to add 
     86``/var/production/django-apps/weblog/`` to your ``PythonPath``. Remember: the 
     87**parent directories** of anything you import directly must be on the Python 
     88path. 
    6589 
    6690.. caution::