3

Hello i have spend 2 days on this error. couldnt figure it out.

an 21 00:19:50 2011] [error] [client 127.0.0.1] ImportError: Could not import settings 'mysite.settings' (Is it on sys.path? Does it have syntax errors?): No module named settings

django.wsgi located in /user/local/django/apache

import os, sys
sys.path.append('/usr/local/django')
os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'

import django.core.handlers.wsgi

application = django.core.handlers.wsgi.WSGIHandler()

my django project named mysite: located in /user/local/django/mysite/scr/ (here contains settings.py init.py and etc...)

apache conf

Alias /media/ /usr/local/django/media
<Directory /usr/local/django/media>
Order deny,allow
Allow from all
</Directory>

<Directory /usr/local/django/apache/>
Order deny,allow
Allow from all
</Directory>



WSGIScriptAlias / /usr/local/django/apache/django.wsgi

i have changed the mysite folder above with permission 777 to avoid any permission issues. and i restart httpd service everytime.

apache starts up and find django.wsig. but it can not find the setting file specifed in it.

and i add the path to $PATH manually and echo it. it is there. and i restart httpd. then the path i added is gone...

anyone knows what is going on?

thanks

Nissan911
  • 293
  • 1
  • 7
  • 17

3 Answers3

3

If settings.py is in /usr/local/django/mysite/scr/, then fairly obviously you should use:

os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.scr.settings'
Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895
2

Original answer was me mistakenly thinking your sys.path was incorrect.

New theory is that you say your settings.py lives in .../django/mysite/scr/, so specifying mysite.settings wouldn't be valid.

Technically, assuming mysite has an __init__.py file, the path to your settings file is mysite.scr.settings

Yuji 'Tomita' Tomita
  • 115,817
  • 29
  • 282
  • 245
  • i tried Order deny,allow Allow from all but it didnt do the magic – Nissan911 Jan 21 '11 at 06:25
  • @Nissan911 -- not in your apache conf, your `sys.path`. `mysite.settings` not found means python can't find `mysite`. – Yuji 'Tomita' Tomita Jan 21 '11 at 06:39
  • i manually add the path sys.path.append. in python. and i print sys.path to verfiy it is there. then i restart httpd. then it shows the same error. then i go back to python and print sys.path. the path i added is gone. – Nissan911 Jan 21 '11 at 07:56
  • @Nissan911, Oops, I'm sorry. Looks like it can't find settings, not mysite. Facepalm. Anyways, in that case, next culprit is that you say your settings file is in `mysite/scr/settings` – Yuji 'Tomita' Tomita Jan 21 '11 at 07:58
1

A couple of things you could try.

Does the test server "runserver' work? If it doesn't it may be that you have an error in your settings file or one of the other files it loads

The order of 'INSTALLED APPS' can be important. For one of my projects this error went away when I changed the order of installed apps.

The answers to this question I asked a bit ago may be helpful. How do I stop getting ImportError: Could not import settings 'mofin.settings' when using django with wsgi?

Community
  • 1
  • 1
Dan
  • 1,536
  • 1
  • 10
  • 20