django import local settings from the server
Question: In my home directory, I have a folder called `local`. In it, there are files
called `__init__.py` and `local_settings.py`. My django app is in a completely
different directory. When the app is **NOT** running in DEBUG mode, I want it
to load the `local_settings.py` file. How can this be acheived? I read the
below:

[python: import a module from a
folder](http://stackoverflow.com/questions/279237/python-import-a-module-from-
a-folder)

[Importing files from different folder in
Python](http://stackoverflow.com/questions/4383571/importing-files-from-
different-folder-in-python)

<http://docs.python.org/tutorial/modules.html>

Basically, those tutorials are allowing to import from another directory, but
what about a completely different working tree? I don't want to keep doing ..,
.., .. etc. Is there a way to goto the home directory?

I tried the following code:

    
    
    import os, sys
    os.chdir(os.path.join(os.getenv("HOME"), 'local'))
    from local_settings import *
    

But i keep seeing errors in my apache error.log for it...


Answer: `os.chdir` just affects the current working directory, which has nothing
whatsoever to do with where Python imports modules from.

What you need to do is to add the the `local` directory to the Pythonpath. You
can either do this from the shell by modifying `PYTHONPATH`, or from inside
Python by modifying `sys.path`:

    
    
    import sys
    sys.path.append(os.path.expanduser("~/local"))
    import local_settings
    

