0

我只是 django 的初学者。我尝试通过链接创建子域。当我运行我的项目时,它显示以下错误

django.core.exceptions.ImproperlyConfigured:无法加载 WSGI 应用程序“netfacer.wsgi.application”;导入模块时出错。

图片 1/2 图片2/2

我的设置.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/'

主机.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")
)

上面链接中的文档也让我感到困惑

4

2 回答 2

0

通常你必须WSGI_APPLICATION在你的设置模块中设置变量,根据代码netfacer.wsgi.application,包含wsgi.py被命名的包netfacer。可能会出现以下问题:

  1. 没有名称的包netfacer- 检查您是否已重命名设置包
  2. netfacer包位于您的<project_root>目录中,检查<project_root>目录是否是PYTHONPATH环境变量的一部分
于 2018-08-02T08:21:47.953 回答
0

添加到您的 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()

确保您的wsgi.py不符合上述配置

检查并删除

从 whitenoise.django 导入 DjangoWhiteNoise
应用程序 = DjangoWhiteNoise(应用程序)

于 2021-01-05T15:43:30.087 回答