Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm deploying a django app, but I can't seem get the settings correct in the Apache configuration. I've put my django app in /path/to/

  DirectoryIndex index.html
  DocumentRoot /path/to/

  <Location "/">
    SetHandler python-program
    PythonHandler django.core.handlers.modpython
    SetEnv DJANGO_SETTINGS_MODULE settings_production
    PythonPath "['/path/to/'] + sys.path"
    PythonDebug On

  <Location "/media/">
    SetHandler None

  <LocationMatch "\.(jpg|gif|png)$">
    SetHandler None

But it's giving me this error:

ImportError: Could not import settings 'settings_production' (Is it on sys.path? Does it have syntax errors?): No module named settings_production

I had a suspicion that my python path is incorrect. Should it be one level above at /path/to/, and thus the setting should be "current.settings_production"

I'm a little stuck, and any help would be appreciated, thanks.

share|improve this question
up vote 1 down vote accepted

The value you use for PythonPath should include the parent directories of all the modules you are going to import in your application. It should also include the parent directory of the DJANGO_SETTINGS_MODULE location.

I good guess would be:

SetEnv DJANGO_SETTINGS_MODULE current.settings_production
PythonPath "['/path/to/'] + sys.path"
share|improve this answer

I agree with rkthkr on the answer to your question but I noticed this.

DocumentRoot /path/to/

Wouldn't that cause a security problem? That would give someone access to your application code. There should be no need to point your DocumentRoot to your application directory. All your static media should be served out of a separate directory. If you are on a Linux system you could symlink your media from your application directory to your DocumentRoot directory.

share|improve this answer
It doesn't seem like it. Unless you turn off mod_python with sethandler, it will interpret it as a route that needs to be passed into And unless it's there in the route, it'll just error out – Wilhelm Jun 9 '09 at 18:26
Irrespective of whether mod_python may intercept the request, it is still very dangerous to stick any source code under DocumentRoot. This is because the DocumentRoot directory would have 'Allow from all', so if Apache was is in some way (mis)configured to allow serving from that location through some other URL, there would be nothing to stop the code being downloaded. So, for self protection, do not do it. – Graham Dumpleton Jun 27 '09 at 11:01

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.