I am just a beginner in django . I tried to create sub-domain by following this link. When I run my project it shows the following error

django.core.exceptions.ImproperlyConfigured: WSGI application 'netfacer.wsgi.application' could not be loaded; Error importing module.

image 1/2 image2/2

my settings.py

import os

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


SECRET_KEY = 'dhxz$csco35cti*^kjru_lum-j*e&$el0rw^!$y0sc_$q8qi-x'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = ['*']


# Application definition

INSTALLED_APPS = [
    'django_hosts',
    'subdomains',
    'administrator.apps.AdministratorConfig',
    'vendoruser.apps.VendoruserConfig',
    'management.apps.ManagementConfig',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',

]

MIDDLEWARE = [
    'django_hosts.middleware.HostsRequestMiddleware',
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'subdomains.middleware.SubdomainURLRoutingMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
    'django_hosts.middleware.HostsResponseMiddleware',

]

SUBDOMAIN_URLCONF = {
    'vendor':'netfacer.urls.vendor'

}


ROOT_URLCONF = 'netfacer.urls'
ROOT_HOSTCONF = 'netfacer.hosts'
DEFAULT_HOST = 'www'
DEFAULT_REDIRECT_URL = "http://www.netfacer.com:8000"

CUSTOM_URL = "netfacer.com:8000"

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.media',
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'netfacer.wsgi.application'

DATABASES = {
    'default':{
        'ENGINE' : 'django.db.backends.postgresql_psycopg2',
        'NAME' : 'alpha',
        'USER' : 'alpha',
        'PASSWORD' : 'alpha',
        'HOST' : 'localhost',
        'PORT': ''
    }
}


AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


STATIC_URL = '/static/'
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, "static"),
    # '/assets/licences/your/images/outside/web/tree/'
]

ENV_PATH = os.path.abspath(os.path.dirname(__file__))
MEDIA_URL = '/assets/'
# MEDIA_URL = '/assets/'

MEDIA_ROOT = os.path.join(ENV_PATH, 'assets/')
# STATIC_ROOT = (os.path.join(BASE_DIR, 'static')

# MEDIA_ROOT  = os.path.join(BASE_DIR, 'uploads')
# MEDIA_URL = '/uploads/'

hosts.py

host_patterns = patterns('',
    host(r'www', settings.ROOT_URLCONF, name='www'),
    host(r'(?!www).*', 'netfacer.hostsconf.urls', name='wildcard'),
    host(r'vendor', 'netfacer.hostsconf.urls', name="vendor")
)

also the documentation in the above link is confusing me

2

There are 2 answers

0
Pavel Minenkov On

Typically you have to set WSGI_APPLICATION variable in your settings module, according to codenetfacer.wsgi.application, package that contain wsgi.py is named netfacer. There may be next issues:

  1. There is not package with name netfacer - check if you have renamed settings package
  2. netfacer package is located in your <project_root> directory, check if <project_root> directory is part of PYTHONPATH environment variable
0
eaithy On

Add to your settings.py
MIDDLEWARE=[
'whitenoise.middleware.WhiteNoiseMiddleware',
]
wsgi.py
import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'your-project-Name.settings')

application = get_wsgi_application()

Ensure your wsgi.py does not fall short of the above configuration

check and Remove

from whitenoise.django import DjangoWhiteNoise
application = DjangoWhiteNoise(application)