Django & Heroku - ImportError: No module named gettingstarted.wsgi
Posted
技术标签:
【中文标题】Django & Heroku - ImportError: No module named gettingstarted.wsgi【英文标题】: 【发布时间】:2017-09-11 13:55:50 【问题描述】:我正在尝试将 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】:您正在引用 gettingstarting
wsgi 模块(文件),它不在您的项目中。
改为将Procfile
的内容更改为:
web: gunicorn PROJECT_NAME.wsgi --log-file -
【讨论】:
澄清应该是web: gunicorn YOUR_APP_NAME.wsgi --log-file -
你是对的,更正了!实际上甚至没有应用程序的名称。因为一个项目由多个应用程序组成,.wsgi
应该是项目的名称(因为它被放置在同名项目的根目录下)。以上是关于Django & Heroku - ImportError: No module named gettingstarted.wsgi的主要内容,如果未能解决你的问题,请参考以下文章
将 Django 开发数据库 (.sql3) 迁移到 Heroku
为什么只有当Debug = False并且db在Heroku上设置为生产数据库时,django才会因服务器500而失败?
你好!我无法连接 django 上的“heroku redis”