gpt4 book ai didi

python - 模块未找到错误: No module named '*.apps'

转载 作者:行者123 更新时间:2023-12-01 09:08:37 32 4
gpt4 key购买 nike

我无法在 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
  • WhiteNoise 版本:3.0
  • settings.py 路径:/home/medhub/MedHub/MedHub/settings.py

settings.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 = '/'

测试.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())

最佳答案

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

关于python - 模块未找到错误: No module named '*.apps' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51842485/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com