Django + Apache:[wsgi:error] ModuleNotFoundError:没有名为django_project1'的模块

时间:2020-11-12 18:11:07

标签: django apache mod-wsgi django-wsgi

使用Apache通过Linode启动我的第一个Django应用程序。一切都进行得很好,直到我不得不完成发布。当我尝试访问站点的IP时,出现“ 500 Internal Server Error”(500内部服务器错误)。根据错误日志,我看到有一个wsgi错误。该错误表明没有找到模块“ django_project1”(这是我的项目的名称)。

我已经看到了很多有关此错误的示例,但是似乎没有关于该错误发生原因的全面解释,而且没有一个示例具有相同的解决方案。感谢您提供任何反馈意见。

下面我包括了我的内容:

错误日志

[Tue Nov 10 19:22:25.784084 2020] [wsgi:error] [pid 63086:tid 140172442277440] [remote 169.45.99.51:49639]   File "<frozen importlib._bootstrap>", line 991, in _find_and_load
[Tue Nov 10 19:22:25.784090 2020] [wsgi:error] [pid 63086:tid 140172442277440] [remote 169.45.99.51:49639]   File "<frozen importlib._bootstrap>", line 961, in _find_and_load_unlocked
[Tue Nov 10 19:22:25.784094 2020] [wsgi:error] [pid 63086:tid 140172442277440] [remote 169.45.99.51:49639]   File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
[Tue Nov 10 19:22:25.784099 2020] [wsgi:error] [pid 63086:tid 140172442277440] [remote 169.45.99.51:49639]   File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
[Tue Nov 10 19:22:25.784104 2020] [wsgi:error] [pid 63086:tid 140172442277440] [remote 169.45.99.51:49639]   File "<frozen importlib._bootstrap>", line 991, in _find_and_load
[Tue Nov 10 19:22:25.784109 2020] [wsgi:error] [pid 63086:tid 140172442277440] [remote 169.45.99.51:49639]   File "<frozen importlib._bootstrap>", line 973, in _find_and_load_unlocked
[Tue Nov 10 19:22:25.784125 2020] [wsgi:error] [pid 63086:tid 140172442277440] [remote 169.45.99.51:49639] ModuleNotFoundError: No module named 'django_project1'
[Tue Nov 10 19:39:56.228148 2020] [mpm_event:notice] [pid 63085:tid 140172470967616] AH00491: caught SIGTERM, shutting down
[Tue Nov 10 19:39:56.343874 2020] [mpm_event:notice] [pid 63212:tid 140164121247040] AH00489: Apache/2.4.46 (Ubuntu) mod_wsgi/4.7.1 Python/3.8 configured -- resuming normal operations
[Tue Nov 10 19:39:56.344269 2020] [core:notice] [pid 63212:tid 140164121247040] AH00094: Command line: '/usr/sbin/apache2'

wsgi.py文件

"""
WSGI config for django_project1 project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/3.1/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'django_project1.settings')

application = get_wsgi_application()

settings.py文件

"""
Django settings for django_project1 project.

Generated by 'django-admin startproject' using Django 3.1.2.

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

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

from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


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

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

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

ALLOWED_HOSTS = []


# Application definition

#add application to this list each time new app is created
INSTALLED_APPS = [
    'blog.apps.BlogConfig',
    'users.apps.UsersConfig',
    #'fluent_contents.plugins.iframe',
    'crispy_forms',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
]

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 = 'django_project1.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        '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 = 'django_project1.wsgi.application'


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

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    }
}


# Password validation
# https://docs.djangoproject.com/en/3.1/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/3.1/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/3.1/howto/static-files/

STATIC_URL = '/static/'

import os

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

CRISPY_TEMPLATE_PACK = 'bootstrap4'

LOGIN_REDIRECT_URL = 'blog-home' #default redirect when a user logs in correctly
LOGIN_URL ='login'

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_USER = 'email'
EMAIL_HOST_PASSWORD = 'password'

django_project.conf

<VirtualHost *:80>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.
        #ServerName www.example.com

        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html

        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf

        Alias /static /home/jpeterson/django_project1/static
        <Directory /home/jpeterson/django_project1/static>
                Require all granted
        </Directory>

        Alias /media /home/jpeterson/django_project1/media
        <Directory /home/jpeterson/django_project1/media>
                Require all granted
        </Directory>

        <Directory /home/jpeterson/django_project1/django_project1>
                <Files wsgi.py>
                        Require all granted
                </Files>
        </Directory>

        WSGIScriptAlias / /home/jpeterson/django_project1/django_project1/wsgi.py
        WSGIDaemonProcess django_app python-path=/home/jpeterson/django_project python-home=/home/jpeterson/django_project1/venv
        WSGIProcessGroup django_app

</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

0 个答案:

没有答案