django wsgi.py cannot recognize settings file
<p>A strange problem occured while trying to configure <code>apache2</code> to serve a Django project via <code>wsgi</code>.</p>

<p>My project is a small to-do list implemented here. <a href="https://github.com/panospet/toDoList" rel="nofollow">https://github.com/panospet/toDoList</a></p>

<p>When apache tries to run <code>wsgi.py</code>, returns this error:</p>

<pre><code>Traceback (most recent call last):
  File "/var/www/toDoList/myToDoList/wsgi.py", line 19, in &lt;module&gt;
    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
</code></pre>

<p>My <code>wsgi.py</code> file is like:</p>

<pre><code>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()
</code></pre>

<p>and also my <code>.conf</code> file inside <code>/etc/apache2/sites-enabled</code>:</p>

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

<p>Based on <a href="https://docs.djangoproject.com/en/1.10/howto/deployment/wsgi/modwsgi/" rel="nofollow">Django documentation</a> You missed the <code>WSGIPythonPath</code>:</p>

<pre><code>WSGIPythonPath /var/www/toDoList
</code></pre>

<p>This line ensures that your project package is available for import on the Python path; in other words, that import mysit works.</p>

python django apache mod-wsgi wsgi