[Webinar] Streamline your web hosting managementRegister Today

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 705
  • Last Modified:

[Ubuntu Django] Could not import settings 'settings'

I try to install django project on Ubuntu with Apache.

Instructions can be found in article:
Sorry for russian description, but commands are onenglish so I think this article can be useful.

I am getting an error:

Fri Dec 06 07:00:51 2013] [error] [client] mod_wsgi (pid=8114): Exception occurred processing WSGI script '/var/www/debianworld_ru/deploy/django.wsgi'.
[Fri Dec 06 07:00:51 2013] [error] [client] Traceback (most recent call last):
[Fri Dec 06 07:00:51 2013] [error] [client]   File "/usr/local/lib/python2.7/dist-packages/Django-1.4.10-py2.7.egg/django/core/handlers/wsgi.py", line 219, in __call__
[Fri Dec 06 07:00:51 2013] [error] [client]     self.load_middleware()
[Fri Dec 06 07:00:51 2013] [error] [client]   File "/usr/local/lib/python2.7/dist-packages/Django-1.4.10-py2.7.egg/django/core/handlers/base.py", line 39, in load_middleware
[Fri Dec 06 07:00:51 2013] [error] [client]     for middleware_path in settings.MIDDLEWARE_CLASSES:
[Fri Dec 06 07:00:51 2013] [error] [client]   File "/usr/local/lib/python2.7/dist-packages/Django-1.4.10-py2.7.egg/django/utils/functional.py", line 184, in inner
[Fri Dec 06 07:00:51 2013] [error] [client]     self._setup()
[Fri Dec 06 07:00:51 2013] [error] [client]   File "/usr/local/lib/python2.7/dist-packages/Django-1.4.10-py2.7.egg/django/conf/__init__.py", line 42, in _setup
[Fri Dec 06 07:00:51 2013] [error] [client]     self._wrapped = Settings(settings_module)
[Fri Dec 06 07:00:51 2013] [error] [client]   File "/usr/local/lib/python2.7/dist-packages/Django-1.4.10-py2.7.egg/django/conf/__init__.py", line 95, in __init__
[Fri Dec 06 07:00:51 2013] [error] [client]     raise ImportError("Could not import settings '%s' (Is it on sys.path?): %s" % (self.SETTINGS_MODULE, e))
[Fri Dec 06 07:00:51 2013] [error] [client] ImportError: Could not import settings 'settings' (Is it on sys.path?): No module named settings

Open in new window

VirtualHost configuration:

<VirtualHost *:80>
    ServerName ibm.com
    ServerAlias www.ibm.com
    ErrorLog    /var/www/debianworld_ru/logs/error_log
    CustomLog   /var/www/debianworld_ru/logs/access_log common

    WSGIScriptAlias / /var/www/debianworld_ru/deploy/django.wsgi

    WSGIDaemonProcess dw-site user=dw group=dw home=/var/www/debianworld_ru/media/ \
                      processes=2 threads=4 maximum-requests=100 display-name=apache-dw-wsgi
    WSGIProcessGroup dw-site

    Alias "/media_admin/" "/usr/lib/python2.7/dist-packages/django/contrib/admin/static/"
    <Location "/media_admin/">
        SetHandler None

    Alias "/media/" "/var/www/debianworld_ru/media/"
    <Location "/media/">
        SetHandler None

Open in new window

Please let me know if you need any additional information to help me.
Thank you.
1 Solution
ChantingWolfAuthor Commented:
A fix:

Aded path to settings file in file deploy/django.wsgi
sys.path.append( "/var/www/debianworld_ru/apps/apps" )

import os, sys

dn = os.path.dirname
PROJECT_ROOT = os.path.abspath( dn(dn(__file__)) )
DJANGO_PROJECT_ROOT = os.path.join(PROJECT_ROOT, 'apps')

sys.path.append( DJANGO_PROJECT_ROOT )
sys.path.append( "/var/www/debianworld_ru/apps/apps" )

os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'

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

Open in new window


Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now