Django& Heroku - ImportError:没有名为gettingstarted.wsgi的模块

时间:2017-04-15 12:44:12

标签: django heroku

我正在尝试将一个Django1.10应用程序部署到Heoroku,然后我跟着this guide添加了所需的配置。

部署后,应用程序崩溃,我得到一个No module named gettingstarted.wsgi ImportError - 完整回溯如下:

2017-04-15T12:22:03.430119+00:00 heroku[web.1]: Starting process with command `gunicorn gettingstarted.wsgi --log-file -`
2017-04-15T12:22:05.349515+00:00 app[web.1]: [2017-04-15 12:22:05 +0000] [4] [INFO] Listening at: http://0.0.0.0:40627 (4)
2017-04-15T12:22:05.349596+00:00 app[web.1]: [2017-04-15 12:22:05 +0000] [4] [INFO] Using worker: sync
2017-04-15T12:22:05.352984+00:00 app[web.1]: [2017-04-15 12:22:05 +0000] [9] [INFO] Booting worker with pid: 9
2017-04-15T12:22:05.355385+00:00 app[web.1]: Traceback (most recent call last):
2017-04-15T12:22:05.349135+00:00 app[web.1]: [2017-04-15 12:22:05 +0000] [4] [INFO] Starting gunicorn 19.7.1
2017-04-15T12:22:05.355386+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py", line 578, in spawn_worker
2017-04-15T12:22:05.355384+00:00 app[web.1]: [2017-04-15 12:22:05 +0000] [9] [ERROR] Exception in worker process
2017-04-15T12:22:05.355387+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/workers/base.py", line 126, in init_process
2017-04-15T12:22:05.355387+00:00 app[web.1]:     self.load_wsgi()
2017-04-15T12:22:05.355386+00:00 app[web.1]:     worker.init_process()
2017-04-15T12:22:05.355388+00:00 app[web.1]:     self.wsgi = self.app.wsgi()
2017-04-15T12:22:05.355389+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
2017-04-15T12:22:05.355389+00:00 app[web.1]:     self.callable = self.load()
2017-04-15T12:22:05.355388+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/workers/base.py", line 135, in load_wsgi
2017-04-15T12:22:05.355390+00:00 app[web.1]:     return self.load_wsgiapp()
2017-04-15T12:22:05.355390+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
2017-04-15T12:22:05.355390+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
2017-04-15T12:22:05.355391+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/util.py", line 352, in import_app
2017-04-15T12:22:05.355391+00:00 app[web.1]:     return util.import_app(self.app_uri)
2017-04-15T12:22:05.355392+00:00 app[web.1]:     __import__(module)
2017-04-15T12:22:05.355467+00:00 app[web.1]: [2017-04-15 12:22:05 +0000] [9] [INFO] Worker exiting (pid: 9)
2017-04-15T12:22:05.372618+00:00 app[web.1]: [2017-04-15 12:22:05 +0000] [4] [INFO] Shutting down: Master
2017-04-15T12:22:05.372681+00:00 app[web.1]: [2017-04-15 12:22:05 +0000] [4] [INFO] Reason: Worker failed to boot.
2017-04-15T12:22:05.355392+00:00 app[web.1]: ImportError: No module named gettingstarted.wsgi
2017-04-15T12:22:05.499273+00:00 heroku[web.1]: Process exited with status 3
2017-04-15T12:22:05.521522+00:00 heroku[web.1]: State changed from starting to crashed

这是我的 settings.py

import os
import dj_database_url


BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
SECRET_KEY = '...'

DEBUG = True

ALLOWED_HOSTS = []

INSTALLED_APPS = [
    'mrp.apps.MrpConfig',
    'django.contrib.humanize',
    'dal',
    'dal_select2',
    'smart_selects',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'wkhtmltopdf',
]

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

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'templates')],
        '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 = 'py_mrp.wsgi.application'

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

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

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',
    },
]

LANGUAGE_CODE = 'it-it'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_THOUSAND_SEPARATOR = True
USE_TZ = True

WKHTMLTOPDF_CMD = '/usr/bin/wkhtmltopdf'
WKHTMLTOPDF_DEBUG = True

def ABS_DIR(rel):
    return os.path.join(BASE_DIR, rel.replace('/', os.path.sep))

PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
STATIC_ROOT = os.path.join(PROJECT_ROOT, 'staticfiles')
STATIC_URL = ABS_DIR('/static/')

STATICFILES_DIRS = (
    os.path.join(PROJECT_ROOT, 'static'),
)

STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'

LOGIN_URL = '/login/'
LOGIN_REDIRECT_URL = '/'
LOGOUT_REDIRECT_URL = '/'

这是我的 Procfile

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

这是我的 wsgi.py

import os

from django.core.wsgi import get_wsgi_application
from whitenoise.django import DjangoWhiteNoise

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

application = get_wsgi_application()
application = DjangoWhiteNoise(application)

这是我的 requirements.txt

appdirs==1.4.3
astroid==1.4.8
attrs==15.2.0
awsebcli==3.7.8
backports.functools-lru-cache==1.3
backports.ssl-match-hostname==3.5.0.1
blessed==1.9.5
botocore==1.4.54
cement==2.8.2
cffi==1.10.0
click==6.7
colorama==0.3.7
configparser==3.5.0
cryptography==1.2.3
dj-database-url==0.4.2
Django==1.10.3
django-autocomplete-light==3.2.1
django-smart-selects==1.3.2
django-wkhtmltopdf==3.1.0
docker-py==1.7.2
dockerpty==0.4.1
docopt==0.6.2
docutils==0.12
enum34==1.1.2
Flask==0.12
gevent==1.1.1
greenlet==0.4.11
gunicorn==19.7.1
idna==2.0
ipaddress==1.0.16
isort==4.2.5
itsdangerous==0.24
Jinja2==2.9.4
jmespath==0.9.0
lazy-object-proxy==1.2.2
locustio==0.7.5
MarkupSafe==0.23
mccabe==0.5.2
msgpack-python==0.4.8
packaging==16.8
pathspec==0.3.4
psycopg2==2.7.1
pyasn1==0.1.9
pyasn1-modules==0.0.7
pycparser==2.17
pylint==1.6.4
pyOpenSSL==0.15.1
pyparsing==2.2.0
pyserial==3.0.1
python-dateutil==2.5.3
PyYAML==3.12
requests==2.9.1
selenium==3.0.0
semantic-version==2.5.0
service-identity==16.0.0
six==1.10.0
texttable==0.8.4
Twisted==16.0.0
virtualenv==15.1.0
wcwidth==0.1.7
websocket-client==0.37.0
Werkzeug==0.11.15
whitenoise==3.3.0
wrapt==1.10.8
zope.interface==4.1.3

项目结构:

.
├── ./db.sqlite3
├── ./manage.py
├── ./mrp
│   ├── ./mrp/admin.py
│   ├── ./mrp/apps.py
│   ├── ./mrp/forms.py
│   ├── ./mrp/__init__.py
│   ├── ./mrp/migrations
│   ├── ./mrp/models.py
│   ├── ./mrp/models.pyc
│   ├── ./mrp/static
│   │   └── ./mrp/static/mrp
│   │       ├── ./mrp/static/mrp/custom.css
│   │       ├── ./mrp/static/mrp/custom.js
│   │       └── ./mrp/static/mrp/images
│   ├── ./mrp/templates
│   ├── ./mrp/tests.py
│   ├── ./mrp/urls.py
│   └── ./mrp/views.py
├── ./Procfile
├── ./py_mrp
│   ├── ./py_mrp/__init__.py
│   ├── ./py_mrp/local_settings.py
│   ├── ./py_mrp/production_settings.py
│   ├── ./py_mrp/settings.py
│   ├── ./py_mrp/urls.py
│   └── ./py_mrp/wsgi.py
├── ./requirements.txt
└── ./templates

谢谢!

1 个答案:

答案 0 :(得分:16)

您正在引用项目中无处的gettingstarting wsgi模块(文件)。

而是将Procfile内容更改为:

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