1

我无法在 PythonAnywhere 上运行我的 django 项目,因为我遇到了 WSGI 问题。我附上有问题的文件。有谁知道这个问题的解决方案?

错误日志:

2018-08-14 12:50:34,868: Error running WSGI application
2018-08-14 12:50:34,868: ModuleNotFoundError: No module named 'test.apps'
2018-08-14 12:50:34,868:   File "/var/www/medhub_pythonanywhere_com_wsgi.py", line 11, in <module>
2018-08-14 12:50:34,869:     application = DjangoWhiteNoise(get_wsgi_application())
2018-08-14 12:50:34,869: 
2018-08-14 12:50:34,869:   File "/home/medhub/MedHub/venv/lib/python3.6/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application
2018-08-14 12:50:34,869:     django.setup(set_prefix=False)
2018-08-14 12:50:34,869: 
2018-08-14 12:50:34,869:   File "/home/medhub/MedHub/venv/lib/python3.6/site-packages/django/__init__.py", line 27, in setup
2018-08-14 12:50:34,869:     apps.populate(settings.INSTALLED_APPS)
2018-08-14 12:50:34,869: 
2018-08-14 12:50:34,869:   File "/home/medhub/MedHub/venv/lib/python3.6/site-packages/django/apps/registry.py", line 85, in populate
2018-08-14 12:50:34,869:     app_config = AppConfig.create(entry)
2018-08-14 12:50:34,869: 
2018-08-14 12:50:34,869:   File "/home/medhub/MedHub/venv/lib/python3.6/site-packages/django/apps/config.py", line 116, in create
2018-08-14 12:50:34,870:     mod = import_module(mod_path)
  • Django 版本:1.10.8
  • 白噪声版本:3.0
  • settings.py 路径:/home/medhub/MedHub/MedHub/settings.py

设置.py 文件:

import os

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
MEDIA_ROOT = os.path.join(BASE_DIR, 'static/media/')
MEDIA_URL = 'static/media/'

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

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '123'

# SECURITY WARNING: don't run with debug turned on in production!
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',
    'user.apps.UserConfig',
    'database.apps.DatabaseConfig',
    'content.apps.ContentConfig',
    'test.apps.TestConfig',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'MedHub.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'templates')]
        ,
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'MedHub.wsgi.application'


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

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}


# Password validation
# https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators

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',
    },
]


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

LANGUAGE_CODE = 'ru-ru'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


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

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

LOGIN_REDIRECT_URL = '/'

test.apps 文件:

# -*- coding: utf-8 -*-
from django.apps import AppConfig


class TestConfig(AppConfig):
    name = 'test'
    verbose_name = 'Тесты'

WSGI 文件:

import os
import sys
path = '/home/medhub/MedHub'
if path not in sys.path:
    sys.path.append(path)

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

from django.core.wsgi import get_wsgi_application
from whitenoise.django import DjangoWhiteNoise
application = DjangoWhiteNoise(get_wsgi_application())
4

1 回答 1

1

'test' 与现有 Python 模块的名称冲突,不能用作应用名称。重命名应用程序会有所帮助。

于 2018-08-14T14:45:50.310 回答