| | 65 | |
|---|
| | 66 | The value you use for ``PythonPath`` should include the parent directories of |
|---|
| | 67 | all the modules you are going to import in your application. It should also |
|---|
| | 68 | include the parent directory of the ``DJANGO_SETTINGS_MODULE`` location. This |
|---|
| | 69 | is exactly the same situation as setting the Python path for interactive |
|---|
| | 70 | usage. Whenever you try to import something, Python will run through all the |
|---|
| | 71 | directories in ``sys.path`` in turn, from first to last, and try to import |
|---|
| | 72 | from each directory until one succeeds. |
|---|
| | 73 | |
|---|
| | 74 | An example might make this clearer. Suppose |
|---|
| | 75 | you 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 |
|---|
| | 79 | need to write your ``PythonPath`` directive as:: |
|---|
| | 80 | |
|---|
| | 81 | PythonPath "['/var/production/django-apps/', '/var/www'] + sys.path" |
|---|
| | 82 | |
|---|
| | 83 | With this path, ``import weblog`` and ``import mysite.settings`` will all |
|---|
| | 84 | work. If you had ``import blogroll`` in your code somewhere and ``blogroll`` |
|---|
| | 85 | lived 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 |
|---|
| | 88 | path. |
|---|