简体   繁体   中英

Django on Apache: ImportError on settings

I am serving a couple of Django sites on an Apache2 server using Virtual Hosts. For one of the sites I keep getting an Internal Server Error with this message in the logs:

[Thu Oct 09 15:11:24.597107 2014] [:error] [pid 8370:tid 140126138050304] [remote 128.30.86.202:15793] ImportError: Could not import settings 'calendar.settings' (Is it on sys.path? Is there an import error in the settings file?): No module named settings

Here is what my calendar/ directory looks like:

|-- calendar
|   |-- forms.py
|   |-- __init__.py
|   |-- models.py
|   |-- settings.py
|   `-- views.py
|-- manage.py
|-- urls.py
`-- wsgi.py

When I print sys.path to my error logs, the calendar and calendar/calendar directories are there.

I have tried running both wsgi.py directory and calendar/settings.py directly and I don't get any import errors. I tried running manage.py shell and again, no import errors.

I have checked that my WSGIPythonPath in /etc/apache2/apache2.conf includes the full path of calendar and calendar/calendar .

I suspect that this is a permissions error. The owner/group for all files in the directory is ubuntu:ubuntu , where ubuntu is the username on the server. Who should the owners be and what should the permissions be? Thanks!

If it's not a permissions issue, ideas about other ways to test this? Thanks!

Put the following in your wsgi.py :

import os
import sys

sys.path.append('/full/path/to/calendar/')
sys.path.append('/full/path/to/calendar/calendar')

os.environ["DJANGO_SETTINGS_MODULE"] = "calendar.settings"

The last line should be actually already there. Uncomment it if needed. If there is a line like:

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "calendar.settings")

then comment it. Try again with these settings and tell us please what happened.

/full/path/to should be replaced with the full path to your project, but that's probably obvious to you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM