On Mon, Jul 4, 2011 at 3:49 PM, candlerb <b.cand...@pobox.com> wrote: > The example given in `django/docs/howto/deployment/modwsgi.txt` shows: > > ~~~~ > os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings' > ... > path = '/path/to/mysite' > if path not in sys.path: > sys.path.append(path) > ~~~~ > > However, when deploying a project I found that I had to include both > the mysite directory and its parent (that is, both `/path/to/mysite` > and `/path/to`), for it to start under Apache, although I didn't have > any problem using `manage.py runserver` when developing. Without this, > apache gave a 500 result and the following in error.log: > > [Mon Jul 04 15:38:42 2011] [error] [client 192.168.122.183] > ImportError: Could not import settings 'mysite.settings' (Is it on > sys.path?): No module named mysite.settings
However you run django, you must configure the appropriate path settings so that it can load your modules. If you have setup your folder layout like this: /path/to foo/ settings.py bar/ Where 'foo' is your project and 'foo.bar' is your app, then you will need to add /path/to to sys.path. If on the other hand 'bar' is how you refer to your app, then you will need to add /path/to/foo to sys.path as well. > > I am running python 2.6.5 under Ubuntu 10.04.2 LTS > > Aside: I found that I could make it work with just `/path/to` in > sys.path if I changed my code to qualify all references to > applications, i.e. use `mysite.app1` and `mysite.app2` everywhere > instead of just `app1` and `app2`. But that's messy. In fact, I would > like to be able to remove all references to `mysite` within the code, > but there are a few places it seems to be necessary; in particular, > whenever I want to pull something out of the toplevel SETTINGS file I > end up writing > > ~~~~ > from mysite import settings > ~~~~ > > Am I missing a trick here? If /path/to/mysite is on the path, would it > be safe to use "import settings" instead of "from mysite import > settings" everywhere? > You're missing several - you should *never* directly import your settings like that. The only reliable and approved way to access your settings is: from django.conf import settings Cheers Tom -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.