在Heroku上部署Python

在Heroku上部署Python

本文介绍了在Heroku上部署Python-django项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在heroku上部署一个小测试应用程序,
它没有错误地被推送到heroku主机,但运行该应用程序会导致应用程序错误。
i检查了英雄日志,并收到以下错误:

I'm trying to deploy a small test app on heroku,It gets pushed to heroku master with no errors but on running the app gives application error.i checked the heroku logs and got the following error :

**2015-07-11T03:56:03.004853+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/workers/base.py", line 118, in init_process
2015-07-11T03:56:03.048862+00:00 app[web.1]: [2015-07-11 03:56:03 +0000] [3] [INFO] Reason: Worker failed to boot.
2015-07-11T03:56:03.004854+00:00 app[web.1]:     self.wsgi = self.app.wsgi()
2015-07-11T03:56:03.004855+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
2015-07-11T03:56:03.004857+00:00 app[web.1]:     self.callable = self.load()
2015-07-11T03:56:03.004858+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
2015-07-11T03:56:03.004859+00:00 app[web.1]:     return self.load_wsgiapp()
2015-07-11T03:56:03.004860+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
2015-07-11T03:56:03.004861+00:00 app[web.1]:     return util.import_app(self.app_uri)
2015-07-11T03:56:03.004863+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/util.py", line 355, in import_app
2015-07-11T03:56:03.004865+00:00 app[web.1]:   File "/app/semicoloninc/wsgi.py", line 13, in <module>
2015-07-11T03:56:03.004864+00:00 app[web.1]:     __import__(module)
2015-07-11T03:56:03.004866+00:00 app[web.1]:     from dj_static import Cling
2015-07-11T03:56:03.004868+00:00 app[web.1]: ImportError: No module named dj_static
2015-07-11T03:56:03.005003+00:00 app[web.1]: [2015-07-11 03:56:03 +0000] [10] [INFO] Worker exiting (pid: 10)
2015-07-11T03:56:03.048672+00:00 app[web.1]: [2015-07-11 03:56:03 +0000] [3] [INFO] Shutting down: Master
2015-07-11T03:56:03.955134+00:00 heroku[web.1]: State changed from up to crashed
2015-07-11T03:56:03.955995+00:00 heroku[web.1]: State changed from crashed to starting
2015-07-11T03:56:03.934809+00:00 heroku[web.1]: Process exited with status 3
2015-07-11T03:56:07.906911+00:00 heroku[web.1]: Starting process with command `gunicorn semicoloninc.wsgi:application`
2015-07-11T03:56:09.283990+00:00 app[web.1]: [2015-07-11 03:56:09 +0000] [3] [INFO] Starting gunicorn 19.3.0
2015-07-11T03:56:09.320937+00:00 app[web.1]: [2015-07-11 03:56:09 +0000] [10] [INFO] Booting worker with pid: 10
2015-07-11T03:56:09.284694+00:00 app[web.1]: [2015-07-11 03:56:09 +0000] [3] [INFO] Listening at: http://0.0.0.0:57450 (3)
2015-07-11T03:56:09.284785+00:00 app[web.1]: [2015-07-11 03:56:09 +0000] [3] [INFO] Using worker: sync
2015-07-11T03:56:09.296813+00:00 app[web.1]: [2015-07-11 03:56:09 +0000] [9] [INFO] Booting worker with pid: 9
2015-07-11T03:56:09.545553+00:00 heroku[web.1]: State changed from starting to up
2015-07-11T03:56:09.937863+00:00 app[web.1]: [2015-07-11 03:56:09 +0000] [9] [ERROR] Exception in worker process:
2015-07-11T03:56:09.937869+00:00 app[web.1]: Traceback (most recent call last):
2015-07-11T03:56:09.937872+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py", line 507, in spawn_worker
2015-07-11T03:56:09.937873+00:00 app[web.1]:     worker.init_process()
2015-07-11T03:56:09.937875+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/workers/base.py", line 118, in init_process
2015-07-11T03:56:09.937878+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
2015-07-11T03:56:09.937876+00:00 app[web.1]:     self.wsgi = self.app.wsgi()
2015-07-11T03:56:09.937879+00:00 app[web.1]:     self.callable = self.load()
2015-07-11T03:56:09.937882+00:00 app[web.1]:     return self.load_wsgiapp()
2015-07-11T03:56:09.937881+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
2015-07-11T03:56:09.937884+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
2015-07-11T03:56:09.937885+00:00 app[web.1]:     return util.import_app(self.app_uri)
2015-07-11T03:56:09.937887+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/util.py", line 355, in import_app
2015-07-11T03:56:09.937888+00:00 app[web.1]:     __import__(module)
2015-07-11T03:56:09.937890+00:00 app[web.1]:   File "/app/semicoloninc/wsgi.py", line 13, in <module>
2015-07-11T03:56:09.937891+00:00 app[web.1]:     from dj_static import Cling
2015-07-11T03:56:09.937893+00:00 app[web.1]: ImportError: No module named dj_static
2015-07-11T03:56:09.937894+00:00 app[web.1]: Traceback (most recent call last):
2015-07-11T03:56:09.937895+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py", line 507, in spawn_worker
2015-07-11T03:56:09.937896+00:00 app[web.1]:     worker.init_process()
2015-07-11T03:56:09.937898+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/workers/base.py", line 118, in init_process
2015-07-11T03:56:09.937899+00:00 app[web.1]:     self.wsgi = self.app.wsgi()
2015-07-11T03:56:09.937900+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
2015-07-11T03:56:09.937901+00:00 app[web.1]:     self.callable = self.load()
2015-07-11T03:56:09.937903+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
2015-07-11T03:56:09.937904+00:00 app[web.1]:     return self.load_wsgiapp()
2015-07-11T03:56:09.937905+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
2015-07-11T03:56:09.937906+00:00 app[web.1]:     return util.import_app(self.app_uri)
2015-07-11T03:56:09.937908+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/util.py", line 355, in import_app
2015-07-11T03:56:09.937910+00:00 app[web.1]:   File "/app/semicoloninc/wsgi.py", line 13, in <module>
2015-07-11T03:56:09.937909+00:00 app[web.1]:     __import__(module)
2015-07-11T03:56:09.937912+00:00 app[web.1]:     from dj_static import Cling
2015-07-11T03:56:09.937913+00:00 app[web.1]: ImportError: No module named dj_static
2015-07-11T03:56:09.938031+00:00 app[web.1]: [2015-07-11 03:56:09 +0000] [9] [INFO] Worker exiting (pid: 9)
2015-07-11T03:56:09.965385+00:00 app[web.1]: [2015-07-11 03:56:09 +0000] [10] [ERROR] Exception in worker process:
2015-07-11T03:56:09.965391+00:00 app[web.1]: Traceback (most recent call last):
2015-07-11T03:56:09.965394+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py", line 507, in spawn_worker
2015-07-11T03:56:09.965396+00:00 app[web.1]:     worker.init_process()
2015-07-11T03:56:09.965397+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/workers/base.py", line 118, in init_process
2015-07-11T03:56:09.965398+00:00 app[web.1]:     self.wsgi = self.app.wsgi()
2015-07-11T03:56:09.965400+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
2015-07-11T03:56:09.965402+00:00 app[web.1]:     self.callable = self.load()
2015-07-11T03:56:09.965404+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
2015-07-11T03:56:09.965405+00:00 app[web.1]:     return self.load_wsgiapp()
2015-07-11T03:56:09.965408+00:00 app[web.1]:     return util.import_app(self.app_uri)
2015-07-11T03:56:09.965410+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/util.py", line 355, in import_app
2015-07-11T03:56:09.965406+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
2015-07-11T03:56:09.965411+00:00 app[web.1]:     __import__(module)
2015-07-11T03:56:09.965414+00:00 app[web.1]:     from dj_static import Cling
2015-07-11T03:56:09.965415+00:00 app[web.1]: ImportError: No module named dj_static
2015-07-11T03:56:09.965412+00:00 app[web.1]:   File "/app/semicoloninc/wsgi.py", line 13, in <module>
2015-07-11T03:56:09.965416+00:00 app[web.1]: Traceback (most recent call last):
2015-07-11T03:56:09.965418+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py", line 507, in spawn_worker
2015-07-11T03:56:09.965419+00:00 app[web.1]:     worker.init_process()
2015-07-11T03:56:09.965420+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/workers/base.py", line 118, in init_process
2015-07-11T03:56:09.965422+00:00 app[web.1]:     self.wsgi = self.app.wsgi()
2015-07-11T03:56:09.965423+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
2015-07-11T03:56:09.965424+00:00 app[web.1]:     self.callable = self.load()
2015-07-11T03:56:09.965425+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
2015-07-11T03:56:09.965427+00:00 app[web.1]:     return self.load_wsgiapp()
2015-07-11T03:56:09.965428+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
2015-07-11T03:56:09.965429+00:00 app[web.1]:     return util.import_app(self.app_uri)
2015-07-11T03:56:09.965430+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/util.py", line 355, in import_app
2015-07-11T03:56:09.965434+00:00 app[web.1]:     __import__(module)
2015-07-11T03:56:09.965435+00:00 app[web.1]:   File "/app/semicoloninc/wsgi.py", line 13, in <module>
2015-07-11T03:56:09.965436+00:00 app[web.1]:     from dj_static import Cling
2015-07-11T03:56:09.965438+00:00 app[web.1]: ImportError: No module named dj_static
2015-07-11T03:56:09.978589+00:00 app[web.1]: [2015-07-11 03:56:09 +0000] [3] [INFO] Shutting down: Master
2015-07-11T03:56:09.965533+00:00 app[web.1]: [2015-07-11 03:56:09 +0000] [10] [INFO] Worker exiting (pid: 10)
2015-07-11T03:56:09.978679+00:00 app[web.1]: [2015-07-11 03:56:09 +0000] [3] [INFO] Reason: Worker failed to boot.
2015-07-11T03:56:10.732554+00:00 heroku[web.1]: State changed from up to crashed
2015-07-11T03:56:10.716153+00:00 heroku[web.1]: Process exited with status 3
2015-07-11T03:56:15.464379+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=fuddi.herokuapp.com request_id=aa45beef-2257-42b4-a4f7-60decf81282d fwd="120.59.67.176" dyno=web.1 connect=5013ms service= status=503 bytes=
2015-07-11T03:56:17.331663+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=fuddi.herokuapp.com request_id=bbd9b863-14b7-4fce-b02e-d13b1c9e1b4c fwd="120.59.67.176" dyno= connect= service= status=503 bytes=
2015-07-11T03:56:18.072135+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=fuddi.herokuapp.com request_id=60f31c6e-55af-440b-8842-f6b7c4727919 fwd="120.59.67.176" dyno= connect= service= status=503 bytes=**

我知道有一些问题lem与进口和gunicorn和wsgi进口。
请帮助我。

I know there is some problem with import and gunicorn and wsgi imports.Please help me out.

我的Procfile是:

my Procfile is:

web: gunicorn semicoloninc.wsgi:application

wsgi.py

import os

from django.core.wsgi import get_wsgi_application
from dj_static import Cling

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "semicoloninc.settings")

settings.py



settings.py

SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')

# Allow all host headers
ALLOWED_HOSTS = ['*']

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
SETTINGS_DIR = os.path.dirname(__file__)

PROJECT_PATH = os.path.join(SETTINGS_DIR, os.pardir)
PROJECT_PATH = os.path.abspath(PROJECT_PATH)


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

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'fhi2%%r#ck5kfl-42#t$bil+hxtlpp7wj42lpd8zv0i#%^2iiz'

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

ALLOWED_HOSTS = []

TEMPLATE_PATH = os.path.join(PROJECT_PATH, 'templates')

STATIC_PATH = os.path.join(PROJECT_PATH, 'static')

# Application definition

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'contactUs',
)

MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'django.middleware.security.SecurityMiddleware',
)

ROOT_URLCONF = 'semicoloninc.urls'

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


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

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}


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

STATIC_URL = '/static/'

STATICFILES_DIRS = (
    STATIC_PATH,
)


application = Cling(get_wsgi_application())


推荐答案

似乎应该从您的日志中清除... ImportError:没有模块名为dj_static
,您不希望阅读官方文档:D

Seems it should be clear from your logs ... ImportError: No module named dj_staticand you don't want read official docs :D

安装收集的软件包:Django,psycopg2,gunicorn,dj-database-url, dj-static ,静态

Installing collected packages: Django, psycopg2, gunicorn, dj-database-url, dj-static, static

成功安装Django psycopg2 gunicorn dj-database-url dj-static static
清理...

Successfully installed Django psycopg2 gunicorn dj-database-url dj-static static Cleaning up...

这篇关于在Heroku上部署Python-django项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-26 14:12