Heroku Django ModuleNotFound应用程序错误

时间:2019-07-09 06:13:02

标签: django heroku

我是与Django合作的初学者,现在尝试部署到Heroku。我能够推送到heroku,他们的服务将我的应用程序识别为python应用程序。但是,当我在浏览器中导航到应用程序时,出现以下错误:

  

应用程序中发生错误,因此无法   服务。如果您是应用程序所有者,请检查日志以获取详细信息。   您可以使用命令heroku logs从Heroku CLI执行此操作   --tail

检查日志,我得到以下信息:

2019-07-09T06:00:29.052294+00:00 app[web.1]: return _bootstrap._gcd_import(name[level:], package, level)
2019-07-09T06:00:29.052301+00:00 app[web.1]: ModuleNotFoundError: No module named 'xxxx'
2019-07-09T06:00:29.052738+00:00 app[web.1]: [2019-07-09 06:00:29 +0000] [10] [INFO] Worker exiting (pid: 10)
2019-07-09T06:00:29.198426+00:00 app[web.1]: [2019-07-09 06:00:29 +0000] [4] [INFO] Shutting down: Master
2019-07-09T06:00:29.198530+00:00 app[web.1]: [2019-07-09 06:00:29 +0000] [4] [INFO] Reason: Worker failed to boot.
2019-07-09T06:00:29.314321+00:00 heroku[web.1]: State changed from up to crashed
2019-07-09T06:00:29.296331+00:00 heroku[web.1]: Process exited with status 3
2019-07-09T06:00:29.937311+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=murmuring-dusk-96030.herokuapp.com request_id=38020b2b-dc63-42aa-91e6-63e1c377eadd fwd="155.93.179.40" dyno= connect= service= status=503 bytes= protocol=https
2019-07-09T06:00:30.382887+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=murmuring-dusk-96030.herokuapp.com request_id=133a6de4-be78-4ac9-9fcf-f65e74c41de3 fwd="155.93.179.40" dyno= connect= service= status=503 bytes= protocol=https

我不确定100%,但是我认为问题与我如何提供静态文件有关?

我设置了带有空白的静态文件,如下所示:

requirements.txt:

dj-database-url==0.5.0
Django==2.2.3
django-heroku==0.3.1
django-tinymce4-lite==1.7.5
gunicorn==19.9.0
jsmin==2.2.2
Pillow==6.0.0
psycopg2==2.8.3
pytz==2019.1
sqlparse==0.3.0
whitenoise==4.1.2 

procfile:

  

web:gunicorn blog.wsgi --log-file-

设置:

import os
import django_heroku
import dj_database_url

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

ALLOWED_HOSTS = ['murmuring-dusk-96030.herokuapp.com', '127.0.0.1:8000']


# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'post',
    'marketing',
    'tinymce'
]

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',
    'whitenoise.middleware.WhiteNoiseMiddleware',
]

ROOT_URLCONF = 'blog.urls'


# Database
# https://docs.djangoproject.com/en/2.2/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/2.2/ref/settings/#auth-password-validators

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

PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
STATIC_URL = '/static/'
MEDIA_URL = '/media/'
STATICFILES_DIRS=[os.path.join(BASE_DIR,'static_in_env')]
VENV_PATH=os.path.dirname(BASE_DIR)
STATIC_ROOT=os.path.join(VENV_PATH,'static_root')
MEDIA_ROOT=os.path.join(VENV_PATH,'media_root')

#  Add configuration for static files storage using whitenoise
STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'

django_heroku.settings(locals())

db_from_env = dj_database_url.config(conn_max_age=500)
DATABASES['default'].update(db_from_env)

对于解决问题的任何建议,我将不胜感激。部署到heroku很简单,但是用Django和Heroku提供静态文件似乎要复杂得多。

0 个答案:

没有答案