Django 应用程序在 Heroku 上崩溃
Django app crashing on Heroku
我正在尝试使用 runserver 将在我的计算机上运行良好的应用程序移植到 Heroku。我是 Django 的新手,之前从未在 Heroku 上部署过应用程序。我不确定我错过了什么。
这是 heroku 错误:
2015-01-18T00:59:22.855761+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 74, in run
2015-01-18T00:59:22.855803+00:00 app[web.1]: WSGIApplication("%(prog)s [OPTIONS] [APP_MODULE]").run()
2015-01-18T00:59:22.855877+00:00 app[web.1]: super(Application, self).run()
2015-01-18T00:59:22.856001+00:00 app[web.1]: self.manage_workers()
2015-01-18T00:59:22.856023+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py", line 477, in manage_workers
2015-01-18T00:59:22.856111+00:00 app[web.1]: self.spawn_workers()
2015-01-18T00:59:22.856132+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py", line 542, in spawn_workers
2015-01-18T00:59:22.855899+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/base.py", line 71, in run
2015-01-18T00:59:22.856230+00:00 app[web.1]: time.sleep(0.1 * random.random())
2015-01-18T00:59:22.856252+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py", line 209, in handle_chld
2015-01-18T00:59:22.856491+00:00 app[web.1]: gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3>
2015-01-18T00:59:22.856303+00:00 app[web.1]: self.reap_workers()
2015-01-18T00:59:22.856324+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py", line 459, in reap_workers
2015-01-18T00:59:22.856408+00:00 app[web.1]: raise HaltServer(reason, self.WORKER_BOOT_ERROR)
2015-01-18T00:59:22.855680+00:00 app[web.1]: Traceback (most recent call last):
2015-01-18T00:59:22.855699+00:00 app[web.1]: File "/app/.heroku/python/bin/gunicorn", line 11, in <module>
2015-01-18T00:59:22.855732+00:00 app[web.1]: sys.exit(run())
2015-01-18T00:59:22.855825+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/base.py", line 185, in run
2015-01-18T00:59:22.855932+00:00 app[web.1]: Arbiter(self).run()
2015-01-18T00:59:22.855953+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py", line 169, in run
2015-01-18T00:59:23.546103+00:00 heroku[web.1]: Process exited with status 1
2015-01-18T00:59:23.550975+00:00 heroku[web.1]: State changed from starting to crashed
2015-01-18T00:59:25.538419+00:00 heroku[api]: Scale to web=1 by thebucketmoney@gmail.com
2015-01-18T01:00:20.825543+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/"
我的 wsgi 文件如下所示:
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "ssbo.settings")
from django.core.wsgi import get_wsgi_application
from whitenoise.django import DjangoWhiteNoise
from dj_static import Cling
application = Cling(get_wsgi_application())
application = DjangoWhiteNoise(application)
我已经创建了几个设置文件(基础、本地、暂存、生产)。我通过设置 DJANGO_SETTINGS_MODULE="ssbo.settings.staging"
在 heroku 上使用暂存
暂存文件:
DEBUG = True
TEMPLATE_DEBUG = True
WSGI_APPLICATION = 'ssbo.wsgi.application'
SESSION_COOKIE_AGE = 300
SECRET_KEY = get_env_variable("SECRET_KEY")
import dj_database_url
DATABASES = {}
DATABASES['default'] = dj_database_url.config()
基本设置文件:
STATIC_ROOT = 'staticfiles'
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)
STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'
BASE_DIR = os.path.join(os.path.dirname(__file__), '..')
requirements.txt:
Django==1.7.3
psycopg2==2.5.4
stripe==1.19.0
gunicorn==19.1.1
dj-database-url==0.3.0
whitenoise==1.0.6
dj-static==0.0.6
过程文件:
web: gunicorn ssbo.wsgi
项目结构:
ssbo
app
migrations
static
app
templates
app
admin.py
forms.py
models.py
views.py
ssbo
settings
base.py
local.py
production.py
staging.py
urls.py
wsgi.py
manage.py
运行 带有 --preload 标志的 gunicorn 服务器揭示了这个问题。 Procfile 的参数不正确。
我正在尝试使用 runserver 将在我的计算机上运行良好的应用程序移植到 Heroku。我是 Django 的新手,之前从未在 Heroku 上部署过应用程序。我不确定我错过了什么。
这是 heroku 错误:
2015-01-18T00:59:22.855761+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 74, in run
2015-01-18T00:59:22.855803+00:00 app[web.1]: WSGIApplication("%(prog)s [OPTIONS] [APP_MODULE]").run()
2015-01-18T00:59:22.855877+00:00 app[web.1]: super(Application, self).run()
2015-01-18T00:59:22.856001+00:00 app[web.1]: self.manage_workers()
2015-01-18T00:59:22.856023+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py", line 477, in manage_workers
2015-01-18T00:59:22.856111+00:00 app[web.1]: self.spawn_workers()
2015-01-18T00:59:22.856132+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py", line 542, in spawn_workers
2015-01-18T00:59:22.855899+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/base.py", line 71, in run
2015-01-18T00:59:22.856230+00:00 app[web.1]: time.sleep(0.1 * random.random())
2015-01-18T00:59:22.856252+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py", line 209, in handle_chld
2015-01-18T00:59:22.856491+00:00 app[web.1]: gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3>
2015-01-18T00:59:22.856303+00:00 app[web.1]: self.reap_workers()
2015-01-18T00:59:22.856324+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py", line 459, in reap_workers
2015-01-18T00:59:22.856408+00:00 app[web.1]: raise HaltServer(reason, self.WORKER_BOOT_ERROR)
2015-01-18T00:59:22.855680+00:00 app[web.1]: Traceback (most recent call last):
2015-01-18T00:59:22.855699+00:00 app[web.1]: File "/app/.heroku/python/bin/gunicorn", line 11, in <module>
2015-01-18T00:59:22.855732+00:00 app[web.1]: sys.exit(run())
2015-01-18T00:59:22.855825+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/base.py", line 185, in run
2015-01-18T00:59:22.855932+00:00 app[web.1]: Arbiter(self).run()
2015-01-18T00:59:22.855953+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py", line 169, in run
2015-01-18T00:59:23.546103+00:00 heroku[web.1]: Process exited with status 1
2015-01-18T00:59:23.550975+00:00 heroku[web.1]: State changed from starting to crashed
2015-01-18T00:59:25.538419+00:00 heroku[api]: Scale to web=1 by thebucketmoney@gmail.com
2015-01-18T01:00:20.825543+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/"
我的 wsgi 文件如下所示:
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "ssbo.settings")
from django.core.wsgi import get_wsgi_application
from whitenoise.django import DjangoWhiteNoise
from dj_static import Cling
application = Cling(get_wsgi_application())
application = DjangoWhiteNoise(application)
我已经创建了几个设置文件(基础、本地、暂存、生产)。我通过设置 DJANGO_SETTINGS_MODULE="ssbo.settings.staging"
在 heroku 上使用暂存暂存文件:
DEBUG = True
TEMPLATE_DEBUG = True
WSGI_APPLICATION = 'ssbo.wsgi.application'
SESSION_COOKIE_AGE = 300
SECRET_KEY = get_env_variable("SECRET_KEY")
import dj_database_url
DATABASES = {}
DATABASES['default'] = dj_database_url.config()
基本设置文件:
STATIC_ROOT = 'staticfiles'
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)
STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'
BASE_DIR = os.path.join(os.path.dirname(__file__), '..')
requirements.txt:
Django==1.7.3
psycopg2==2.5.4
stripe==1.19.0
gunicorn==19.1.1
dj-database-url==0.3.0
whitenoise==1.0.6
dj-static==0.0.6
过程文件:
web: gunicorn ssbo.wsgi
项目结构:
ssbo
app
migrations
static
app
templates
app
admin.py
forms.py
models.py
views.py
ssbo
settings
base.py
local.py
production.py
staging.py
urls.py
wsgi.py
manage.py
运行 带有 --preload 标志的 gunicorn 服务器揭示了这个问题。 Procfile 的参数不正确。