banzai banzai - 3 months ago 16
Apache Configuration Question

django wsgi.py cannot recognize settings file

A strange problem occured while trying to configure

apache2
to serve a Django project via
wsgi
.

My project is a small to-do list implemented here. https://github.com/panospet/toDoList

When apache tries to run
wsgi.py
, returns this error:

Traceback (most recent call last):
File "/var/www/toDoList/myToDoList/wsgi.py", line 19, in <module>
application = get_wsgi_application()
File "/usr/local/lib/python2.7/dist-packages/django/core/wsgi.py", line 13, in get_wsgi_application
django.setup(set_prefix=False)
File "/usr/local/lib/python2.7/dist-packages/django/__init__.py", line 22, in setup
configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 53, in __getattr__
self._setup(name)
File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 41, in _setup
self._wrapped = Settings(settings_module)
File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 97, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
ImportError: No module named myToDoList.settings


My
wsgi.py
file is like:

import os
import sys

sys.path.append(' /var/www/toDoList')
sys.path.append(' /var/www/toDoList/myToDoList')

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

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()


and also my
.conf
file inside
/etc/apache2/sites-enabled
:

<VirtualHost *:80>
DocumentRoot "/var/www/toDoList"
ServerName blahblah
WSGIDaemonProcess todolist user=test group=test threads=5
WSGIScriptAlias / /var/www/toDoList/myToDoList/wsgi.py
<Location /todolist>
WSGIProcessGroup todolist
</Location>
<Directory /var/www/toDoList/toDoList>
Order allow,deny
Allow from all
</Directory>
Alias /static /var/www/toDoList/myToDoList/static/
<Directory /var/www/toDoList/myToDoList/static>
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Answer

remove that space in sys.path.append

sys.path.append('/var/www/toDoList')
sys.path.append('/var/www/toDoList/myToDoList')