3

I am trying to host a basic Django-Oscar app on a subdomain on an Amazon EC2 instance. It is working file on the local server but on hosting it is giving the following error as per

Apache error log

 mod_wsgi (pid=13645): Target WSGI script '/home/ubuntu/frobshop.com/frobshop/frobshop/wsgi.py' cannot be loaded as Python module.
 mod_wsgi (pid=13645): Exception occurred processing WSGI script '/home/ubuntu/frobshop.com/frobshop/frobshop/wsgi.py'.
 Traceback (most recent call last):
  File "/home/ubuntu/frobshop.com/frobshop/frobshop/wsgi.py", line 14, in <module>
    application = get_wsgi_application()
   File "/usr/local/lib/python2.7/dist-packages/django/core/wsgi.py", line 14, in get_wsgi_application
  django.setup()
   File "/usr/local/lib/python2.7/dist-packages/django/__init__.py", line 20, in setup
    configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
   File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 46, in __getattr__
     self._setup(name)
   File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 42, in _setup
     self._wrapped = Settings(settings_module)
   File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 98, in __init__
     % (self.SETTINGS_MODULE, e)
ImportError: Could not import settings 'frobshop.settings' (Is it on sys.path? Is there an import error in the settings file?): No module named frobshop.settings

My settings.py file is :

"""
Django settings for frobshop project.

For more information on this file, see
https://docs.djangoproject.com/en/1.7/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.7/ref/settings/
"""

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
import oscar
from oscar import OSCAR_MAIN_TEMPLATE_DIR
from oscar import get_core_apps
from oscar.defaults import *
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
location = lambda x: os.path.join(
    os.path.dirname(os.path.realpath(__file__)), x)


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.7/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'h9(c0lu!m8%5&qy)boa(l&32x4&0#(330zz-v%3%a_vu4b4hm+'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
OSCAR_SHOP_NAME = ""
OSCAR_HOMEPAGE = reverse_lazy('promotions:home')
# USE_LESS = True

TEMPLATE_DEBUG = True
THUMBNAIL_DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.sites',
    'django.contrib.flatpages',
    'compressor'
] + get_core_apps()

SITE_ID = 1

TEMPLATE_CONTEXT_PROCESSORS = (
    "django.contrib.auth.context_processors.auth",
    "django.core.context_processors.request",
    "django.core.context_processors.debug",
    "django.core.context_processors.i18n",
    "django.core.context_processors.media",
    "django.core.context_processors.static",
    "django.core.context_processors.tz",
    "django.contrib.messages.context_processors.messages",
    'oscar.apps.search.context_processors.search_form',
    'oscar.apps.promotions.context_processors.promotions',
    'oscar.apps.checkout.context_processors.checkout',
    'oscar.apps.customer.notifications.context_processors.notifications',
    'oscar.core.context_processors.metadata',
)

MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'oscar.apps.basket.middleware.BasketMiddleware',
    'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware',
)

AUTHENTICATION_BACKENDS = (
    'oscar.apps.customer.auth_backends.EmailBackend',
    'django.contrib.auth.backends.ModelBackend',
)

TEMPLATE_DIRS = (
    location('templates'),
    OSCAR_MAIN_TEMPLATE_DIR,
)

STATICFILES_DIRS = (
    os.path.join(BASE_DIR, '/static/'),
)

# COMPRESS_PRECOMPILERS = (
#     ('text/less', 'lessc {infile} {outfile}'),
# )

STATICFILES_FINDERS = (
    'compressor.finders.CompressorFinder',
)
HAYSTACK_CONNECTIONS = {
    'default': {
        'ENGINE': 'haystack.backends.simple_backend.SimpleEngine',
    },
}

# HAYSTACK_CONNECTIONS = {
#     'default': {
#         'ENGINE': 'haystack.backends.solr_backend.SolrEngine',
#         'URL': 'http://127.0.0.1:8983/solr',
#         'INCLUDE_SPELLING': True,
#     },
# }

ROOT_URLCONF = 'frobshop.urls'

WSGI_APPLICATION = 'frobshop.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.7/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'frobshop',
        'USER': 'root',
        'PASSWORD': 'password',
        'HOST': 'localhost',
        'PORT': '3306',
        'ATOMIC_REQUESTS': True,
    }
}

# Internationalization
# https://docs.djangoproject.com/en/1.7/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.7/howto/static-files/

STATIC_URL = '/static/'
STATIC_ROOT = BASE_DIR + "/static/"
MEDIA_URL = '/media/'
MEDIA_ROOT = location("media")

OSCAR_INITIAL_ORDER_STATUS = 'Pending'
OSCAR_INITIAL_LINE_STATUS = 'Pending'
OSCAR_ORDER_STATUS_PIPELINE = {
    'Pending': ('Being processed', 'Cancelled',),
    'Being processed': ('Processed', 'Cancelled',),
    'Cancelled': (),
}

The apache conf file is :

WSGIScriptAlias / /home/ubuntu/frobshop.com/frobshop/frobshop/wsgi.py
WSGIPythonPath /home/ubuntu/frobshop.com/frobshop

<VirtualHost *:80>

        Alias /static/ /home/ubuntu/frobshop.com/static/
        Alias /media/ /home/ubuntu/frobshop.com/media/


        ServerName "The subdomain I am using"

        <Directory /home/ubuntu/frobshop.com/frobshop/frobshop>
                <Files wsgi.py>
                        Order deny,allow
                        Require all granted
                </Files>
        </Directory>

        <Directory /home/ubuntu/frobshop.com/frobshop/static>
                Require all granted
        </Directory>

        <Directory /home/ubuntu/frobshop.com/frobshop/media>
                Require all granted
        </Directory>

        <Directory /home/ubuntu/frobshop.com/media>
                Require all granted
        </Directory>

        <Directory /home/ubuntu/frobshop.com/frobshop/staticfiles>
                Require all granted
        </Directory>

</VirtualHost>

Can anyone guide through with what/why is the error?

Graham Dumpleton
  • 57,726
  • 6
  • 119
  • 134
ofnowhere
  • 1,114
  • 2
  • 16
  • 40
  • Have you tried everything mentioned in the link http://stackoverflow.com/questions/1411417/how-do-i-stop-getting-importerror-could-not-import-settings-mofin-settings-wh ? – vijayalakshmi d Apr 28 '15 at 22:47
  • @vijayalakshmid yes almost all of them, which I thought could cause the problem – ofnowhere Apr 28 '15 at 23:20

2 Answers2

4

I can't comment because I don't have enough rep. This issue is clearly that the settings.py file is not being found based on where your wsgi.py file says it's going to be.

Therefore we need to see your project directory structure. It should look like this.

YourProject
   > FrobShop
     settings.py
   wsgi.py

The good news is the wsgi file is being found by your virtualenv, it's the wsgi that can't find the settings.

PythonIsGreat
  • 7,529
  • 7
  • 21
  • 26
3

Make sure you have included the file __init__.py in every directory containing and leading up to your settings file.

If you do not include an __init__.py file in your directory, python version < 3 does not recognize the directory as a module.

sshirgao
  • 291
  • 3
  • 9