django 应用程序的 Heroku 构建成功但打开应用程序引发错误

时间:2021-02-25 14:30:29

标签: django heroku

Django 应用程序在本地运行正常,并成功构建到 heroku,但应用程序未显示。错误日志说

No module named 'my_app.wsgi'

我不知所措。我尝试了不同的应用名称和 procfile 位置。

这是Procfile。由 heroku 找到并显示为资源动态。

web: gunicorn my_app.wsgi

这是文件结构

file structure

这是 wsgi.py(如果相关)

import os

from django.core.wsgi import get_wsgi_application

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

application = get_wsgi_application()

这是heroku错误日志

2021-02-25T14:11:44.731878+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1007, 
in _find_and_load
2021-02-25T14:11:44.731878+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 984, in _find_and_load_unlocked
2021-02-25T14:11:44.731879+00:00 app[web.1]: ModuleNotFoundError: No module named 'my_app.wsgi'
2021-02-25T14:11:44.732085+00:00 app[web.1]: [2021-02-25 14:11:44 +0000] [7] [INFO] Worker exiting (pid: 7)
2021-02-25T14:11:44.764764+00:00 app[web.1]: [2021-02-25 14:11:44 +0000] [4] [INFO] Shutting down: Master
2021-02-25T14:11:44.764844+00:00 app[web.1]: [2021-02-25 14:11:44 +0000] [4] [INFO] Reason: Worker failed to boot.
2021-02-25T14:11:44.849187+00:00 heroku[web.1]: Process exited with status 3
2021-02-25T14:11:44.920807+00:00 heroku[web.1]: State changed from starting to crashed        
2021-02-25T14:11:44.923622+00:00 heroku[web.1]: State changed from crashed to starting        
2021-02-25T14:11:55.765297+00:00 heroku[web.1]: Starting process with command `gunicorn my_app.wsgi`
2021-02-25T14:11:58.971074+00:00 app[web.1]: [2021-02-25 14:11:58 +0000] [4] [INFO] Starting gunicorn 20.0.4
2021-02-25T14:11:58.971543+00:00 app[web.1]: [2021-02-25 14:11:58 +0000] [4] [INFO] Listening 
at: http://0.0.0.0:41265 (4)
2021-02-25T14:11:58.971644+00:00 app[web.1]: [2021-02-25 14:11:58 +0000] [4] [INFO] Using worker: sync
2021-02-25T14:11:58.976354+00:00 app[web.1]: [2021-02-25 14:11:58 +0000] [7] [INFO] Booting worker with pid: 7
2021-02-25T14:11:58.981794+00:00 app[web.1]: [2021-02-25 14:11:58 +0000] [7] [ERROR] Exception in worker process
2021-02-25T14:11:58.981796+00:00 app[web.1]: Traceback (most recent call last):
2021-02-25T14:11:58.981796+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
2021-02-25T14:11:58.981797+00:00 app[web.1]: worker.init_process()
2021-02-25T14:11:58.981797+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/workers/base.py", line 119, in init_process
2021-02-25T14:11:58.981798+00:00 app[web.1]: self.load_wsgi()
2021-02-25T14:11:58.981798+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/workers/base.py", line 144, in load_wsgi
2021-02-25T14:11:58.981798+00:00 app[web.1]: self.wsgi = self.app.wsgi()
2021-02-25T14:11:58.981799+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/app/base.py", line 67, in wsgi
2021-02-25T14:11:58.981799+00:00 app[web.1]: self.callable = self.load()
2021-02-25T14:11:58.981800+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/app/wsgiapp.py", line 49, in load
2021-02-25T14:11:58.981800+00:00 app[web.1]: return self.load_wsgiapp()
2021-02-25T14:11:58.981801+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/app/wsgiapp.py", line 39, in load_wsgiapp
2021-02-25T14:11:58.981801+00:00 app[web.1]: return util.import_app(self.app_uri)
2021-02-25T14:11:58.981802+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/util.py", line 358, in import_app
2021-02-25T14:11:58.981802+00:00 app[web.1]: mod = importlib.import_module(module)
2021-02-25T14:11:58.981802+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/importlib/__init__.py", line 127, in import_module
2021-02-25T14:11:58.981803+00:00 app[web.1]: return _bootstrap._gcd_import(name[level:], package, level)
2021-02-25T14:11:58.981804+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1030, 
in _gcd_import
2021-02-25T14:11:58.981804+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1007, 
in _find_and_load
2021-02-25T14:11:58.981804+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 984, in _find_and_load_unlocked
2021-02-25T14:11:58.981805+00:00 app[web.1]: ModuleNotFoundError: No module named 'my_app.wsgi'
2021-02-25T14:11:58.981904+00:00 app[web.1]: [2021-02-25 14:11:58 +0000] [7] [INFO] Worker exiting (pid: 7)
2021-02-25T14:11:59.017648+00:00 app[web.1]: [2021-02-25 14:11:59 +0000] [8] [INFO] Booting worker with pid: 8
2021-02-25T14:11:59.024857+00:00 app[web.1]: [2021-02-25 14:11:59 +0000] [8] [ERROR] Exception in worker process
2021-02-25T14:11:59.024859+00:00 app[web.1]: Traceback (most recent call last):
2021-02-25T14:11:59.024859+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
2021-02-25T14:11:59.024860+00:00 app[web.1]: worker.init_process()
2021-02-25T14:11:59.024860+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/workers/base.py", line 119, in init_process
2021-02-25T14:11:59.024861+00:00 app[web.1]: self.load_wsgi()
2021-02-25T14:11:59.024861+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/workers/base.py", line 144, in load_wsgi
2021-02-25T14:11:59.024861+00:00 app[web.1]: self.wsgi = self.app.wsgi()
2021-02-25T14:11:59.024862+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/app/base.py", line 67, in wsgi
2021-02-25T14:11:59.024862+00:00 app[web.1]: self.callable = self.load()
2021-02-25T14:11:59.024862+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/app/wsgiapp.py", line 49, in load
2021-02-25T14:11:59.024863+00:00 app[web.1]: return self.load_wsgiapp()
2021-02-25T14:11:59.024863+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/app/wsgiapp.py", line 39, in load_wsgiapp
2021-02-25T14:11:59.024863+00:00 app[web.1]: return util.import_app(self.app_uri)
2021-02-25T14:11:59.024863+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/util.py", line 358, in import_app
2021-02-25T14:11:59.024864+00:00 app[web.1]: mod = importlib.import_module(module)
2021-02-25T14:11:59.024864+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/importlib/__init__.py", line 127, in import_module
2021-02-25T14:11:59.024864+00:00 app[web.1]: return _bootstrap._gcd_import(name[level:], package, level)
2021-02-25T14:11:59.024865+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1030, 
in _gcd_import
2021-02-25T14:11:59.024865+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1007, 
in _find_and_load
2021-02-25T14:11:59.024865+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 984, in _find_and_load_unlocked
2021-02-25T14:11:59.024865+00:00 app[web.1]: ModuleNotFoundError: No module named 'my_app.wsgi'
2021-02-25T14:11:59.024987+00:00 app[web.1]: [2021-02-25 14:11:59 +0000] [8] [INFO] Worker exiting (pid: 8)
2021-02-25T14:11:59.065517+00:00 app[web.1]: Traceback (most recent call last):
2021-02-25T14:11:59.065525+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/arbiter.py", line 202, in run
2021-02-25T14:11:59.065854+00:00 app[web.1]: self.manage_workers()
2021-02-25T14:11:59.065855+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/arbiter.py", line 545, in manage_workers
2021-02-25T14:11:59.066170+00:00 app[web.1]: self.spawn_workers()
2021-02-25T14:11:59.066175+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/arbiter.py", line 617, in spawn_workers
2021-02-25T14:11:59.066538+00:00 app[web.1]: time.sleep(0.1 * random.random())
2021-02-25T14:11:59.066571+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/arbiter.py", line 242, in handle_chld
2021-02-25T14:11:59.066785+00:00 app[web.1]: self.reap_workers()
2021-02-25T14:11:59.066786+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/arbiter.py", line 525, in reap_workers
2021-02-25T14:11:59.066978+00:00 app[web.1]: raise HaltServer(reason, self.WORKER_BOOT_ERROR) 
2021-02-25T14:11:59.067054+00:00 app[web.1]: gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3>
2021-02-25T14:11:59.067057+00:00 app[web.1]:
2021-02-25T14:11:59.067057+00:00 app[web.1]: During handling of the above exception, another exception occurred:
2021-02-25T14:11:59.067058+00:00 app[web.1]:
2021-02-25T14:11:59.067079+00:00 app[web.1]: Traceback (most recent call last):
2021-02-25T14:11:59.067081+00:00 app[web.1]: File "/app/.heroku/python/bin/gunicorn", line 8, 
in <module>
2021-02-25T14:11:59.067194+00:00 app[web.1]: sys.exit(run())
2021-02-25T14:11:59.067217+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/app/wsgiapp.py", line 58, in run
2021-02-25T14:11:59.067330+00:00 app[web.1]: WSGIApplication("%(prog)s [OPTIONS] [APP_MODULE]").run()
2021-02-25T14:11:59.067355+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/app/base.py", line 228, in run
2021-02-25T14:11:59.067498+00:00 app[web.1]: super().run()
2021-02-25T14:11:59.067521+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/app/base.py", line 72, in run
2021-02-25T14:11:59.067632+00:00 app[web.1]: Arbiter(self).run()
2021-02-25T14:11:59.067654+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/arbiter.py", line 229, in run
2021-02-25T14:11:59.067788+00:00 app[web.1]: self.halt(reason=inst.reason, exit_status=inst.exit_status)
2021-02-25T14:11:59.067810+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/arbiter.py", line 342, in halt
2021-02-25T14:11:59.068000+00:00 app[web.1]: self.stop()
2021-02-25T14:11:59.068000+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/arbiter.py", line 393, in stop
2021-02-25T14:11:59.068160+00:00 app[web.1]: time.sleep(0.1)
2021-02-25T14:11:59.068183+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/arbiter.py", line 242, in handle_chld
2021-02-25T14:11:59.068326+00:00 app[web.1]: self.reap_workers()
2021-02-25T14:11:59.068327+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/arbiter.py", line 525, in reap_workers
2021-02-25T14:11:59.068518+00:00 app[web.1]: raise HaltServer(reason, self.WORKER_BOOT_ERROR) 
2021-02-25T14:11:59.068570+00:00 app[web.1]: gunicorn.errors.HaltServer: <HaltServer 'Worker f2021-02-25T14:11:59.068570+00:00 app[web.1]: gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3>
2021-02-25T14:11:59.135051+00:00 heroku[web.1]: Process exited with status 1
2021-02-25T14:11:59.211866+00:00 heroku[web.1]: State changed from starting to crashed
2021-02-25T14:12:05.924693+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=dwight-london-protocols.herokuapp.com request_id=e8d14579-f3dc-43e6-91a3-298d9e8dbc97 fwd="82.34.156.183" dyno= connect= service= status=503 bytes= protocol=https
2021-02-25T14:12:06.173468+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=dwight-london-protocols.herokuapp.com request_id=fe00caf9-9da7-41c2-9c57-dafee2337139 fwd="82.34.156.183" dyno= connect= service= status=503 bytes= protocol=https
2021-02-25T14:17:16.066415+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=dwight-london-protocols.herokuapp.com request_id=55f7521b-3172-4ad8-825f-33afa04da5f5 fwd="82.34.156.183" dyno= connect= service= status=503 bytes= protocol=https
2021-02-25T14:17:16.658554+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=dwight-london-protocols.herokuapp.com request_id=5fb56c49-de44-4c67-8217-f79436ba0183 fwd="82.34.156.183" dyno= connect= service= status=503 bytes= protocol=https

这是settings.py

"""
Django settings for my_app project.

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

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

For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.0/ref/settings/
"""
import django_heroku
import os
from decouple import config
import dj_database_url

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


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

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = config("SECRET_KEY")


# 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',
    'todo_list',
    'my_app',
    'crispy_forms',
    'django_extensions',
    'django.contrib.sites',  
    'allauth',   
    'allauth.account',   
    'allauth.socialaccount',   
    'allauth.socialaccount.providers.google'   
]


CRISPY_TEMPLATE_PACK = 'bootstrap4'

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'whitenoise.middleware.WhiteNoiseMiddleware',
    '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 = 'my_app.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 = 'my_app.wsgi.application'


# Database
# https://docs.djangoproject.com/en/3.0/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/3.0/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.0/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.0/howto/static-files/

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

STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'

#for google useer authentication

AUTHENTICATION_BACKENDS = (
 'django.contrib.auth.backends.ModelBackend',
 'allauth.account.auth_backends.AuthenticationBackend',
 )

SITE_ID = 2
LOGIN_REDIRECT_URL = '/'

SOCIALACCOUNT_PROVIDERS = {
    'google': {
        'SCOPE': [
            'profile',
            'email',
        ],
        'AUTH_PARAMS': {
            'access_type': 'online',
        }
    }
}

# # Activate Django-Heroku.
django_heroku.settings(locals())

1 个答案:

答案 0 :(得分:0)

通过更改 Procfile 路径解决的错误

web: gunicorn --chdir my_app my_app.wsgi