Mod_python error: ImportError: Could not import settings

R0b0tn1k picture R0b0tn1k · Jun 7, 2009 · Viewed 12.1k times · Source

Trying to get Django to work with Apache, and I'm getting the following error:

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

My Django app is located in /home/user/django/MyDjangoApp/

My httpd.conf Location section looks like:

<Location "/MyDjangoApp/">
  SetHandler python-program
  PythonHandler django.core.handlers.modpython
  SetEnv DJANGO_SETTINGS_MODULE MKSearch.settings
  PythonOption django.root /MyDjangoApp
  PythonPath "['/home/user/django/MyDjangoApp/','/var/www'] + sys.path" 
  PythonDebug On
</Location>

Please tell me how to correct the location section to make Django work?

Answer

sleepyjames picture sleepyjames · Jun 8, 2009

I think mod_python is looking for settings in the MKSearch module which doesn't exist in side the /home/user/django/MyDjangoApp directory. Try adding the parent dir to the PythonPath directive as below:

<Location "/MyDjangoApp/">
  SetHandler python-program
  PythonHandler django.core.handlers.modpython
  SetEnv DJANGO_SETTINGS_MODULE MKSearch.settings
  PythonOption django.root /MyDjangoApp
  PythonPath "['/home/user/django/', '/home/user/django/MyDjangoApp,'/var/www'] + sys.path" 
  PythonDebug On
</Location>

Or remove the module name from the DJANGO_SETTINGS_MODULE env var as below:

<Location "/MyDjangoApp/">
  SetHandler python-program
  PythonHandler django.core.handlers.modpython
  SetEnv DJANGO_SETTINGS_MODULE settings
  PythonOption django.root /MyDjangoApp
  PythonPath "['/home/user/django/MyDjangoApp,'/var/www'] + sys.path" 
  PythonDebug On
</Location>