我正在将我的django项目部署到Heroku。 但秘密密钥问题不断涌现!
可能出错了什么?任何建议将不胜感激,谢谢!
State changed from crashed to starting
Nov 20 16:37:53 heroku_app heroku/web.1: Starting process with command `gunicorn config.wsgi:application --env DJANGO_SETTINGS_MODULE='config.settings.production'`
Nov 20 16:37:56 heroku_app heroku/web.1: State changed from starting to up
Nov 20 16:37:56 heroku_app app/web.1: [2016-11-20 05:37:55 +0000] [4] [INFO] Starting gunicorn 19.5.0
Nov 20 16:37:56 heroku_app app/web.1: [2016-11-20 05:37:55 +0000] [4] [INFO] Listening at: http://0.0.0.0:46247 (4)
Nov 20 16:37:56 heroku_app app/web.1: [2016-11-20 05:37:55 +0000] [4] [INFO] Using worker: sync
Nov 20 16:37:56 heroku_app app/web.1: [2016-11-20 05:37:55 +0000] [10] [INFO] Booting worker with pid: 10
Nov 20 16:37:56 heroku_app app/web.1: [2016-11-20 05:37:55 +0000] [11] [INFO] Booting worker with pid: 11
Nov 20 16:37:56 heroku_app app/web.1: [2016-11-20 05:37:56 +0000] [10] [ERROR] Exception in worker process
Nov 20 16:37:56 heroku_app app/web.1: Traceback (most recent call last):
Nov 20 16:37:56 heroku_app app/web.1: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py", line 517, in spawn_worker
Nov 20 16:37:56 heroku_app app/web.1: worker.init_process()
Nov 20 16:37:56 heroku_app app/web.1: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/workers/base.py", line 122, in init_process
Nov 20 16:37:56 heroku_app app/web.1: self.load_wsgi()
Nov 20 16:37:56 heroku_app app/web.1: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/workers/base.py", line 132, in load_wsgi
Nov 20 16:37:56 heroku_app app/web.1: self.wsgi = self.app.wsgi()
Nov 20 16:37:56 heroku_app app/web.1: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
Nov 20 16:37:56 heroku_app app/web.1: self.callable = self.load()
Nov 20 16:37:56 heroku_app app/web.1: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
Nov 20 16:37:56 heroku_app app/web.1: return self.load_wsgiapp()
Nov 20 16:37:56 heroku_app app/web.1: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
Nov 20 16:37:56 heroku_app app/web.1: return util.import_app(self.app_uri)
Nov 20 16:37:56 heroku_app app/web.1: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/util.py", line 357, in import_app
Nov 20 16:37:56 heroku_app app/web.1: __import__(module)
Nov 20 16:37:56 heroku_app app/web.1: File "/app/config/wsgi.py", line 31, in <module>
Nov 20 16:37:56 heroku_app app/web.1: application = get_wsgi_application()
Nov 20 16:37:56 heroku_app app/web.1: File "/app/.heroku/python/lib/python2.7/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application
Nov 20 16:37:56 heroku_app app/web.1: django.setup()
Nov 20 16:37:56 heroku_app app/web.1: File "/app/.heroku/python/lib/python2.7/site-packages/django/__init__.py", line 17, in setup
Nov 20 16:37:56 heroku_app app/web.1: configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
Nov 20 16:37:56 heroku_app app/web.1: File "/app/.heroku/python/lib/python2.7/site-packages/django/conf/__init__.py", line 55, in __getattr__
Nov 20 16:37:56 heroku_app app/web.1: self._setup(name)
Nov 20 16:37:56 heroku_app app/web.1: File "/app/.heroku/python/lib/python2.7/site-packages/django/conf/__init__.py", line 43, in _setup
Nov 20 16:37:56 heroku_app app/web.1: self._wrapped = Settings(settings_module)
Nov 20 16:37:56 heroku_app app/web.1: File "/app/.heroku/python/lib/python2.7/site-packages/django/conf/__init__.py", line 99, in __init__
Nov 20 16:37:56 heroku_app app/web.1: mod = importlib.import_module(self.SETTINGS_MODULE)
Nov 20 16:37:56 heroku_app app/web.1: File "/app/.heroku/python/lib/python2.7/importlib/__init__.py", line 37, in import_module
Nov 20 16:37:56 heroku_app app/web.1: __import__(name)
Nov 20 16:37:56 heroku_app app/web.1: File "/app/config/settings/production.py", line 24, in <module>
Nov 20 16:37:56 heroku_app app/web.1: SECRET_KEY = env('DJANGO_SECRET_KEY')
Nov 20 16:37:56 heroku_app app/web.1: File "/app/.heroku/python/lib/python2.7/site-packages/environ/environ.py", line 111, in __call__
Nov 20 16:37:56 heroku_app app/web.1: return self.get_value(var, cast=cast, default=default, parse_default=parse_default)
Nov 20 16:37:56 heroku_app app/web.1: File "/app/.heroku/python/lib/python2.7/site-packages/environ/environ.py", line 253, in get_value
Nov 20 16:37:56 heroku_app app/web.1: raise ImproperlyConfigured(error_msg)
Nov 20 16:37:56 heroku_app app/web.1: ImproperlyConfigured: Set the DJANGO_SECRET_KEY environment variable
Nov 20 16:37:56 heroku_app app/web.1: [2016-11-20 05:37:56 +0000] [11] [ERROR] Exception in worker process
Nov 20 16:37:56 heroku_app app/web.1: Traceback (most recent call last):
Nov 20 16:37:56 heroku_app app/web.1: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py", line 517, in spawn_worker
Nov 20 16:37:56 heroku_app app/web.1: worker.init_process()
Nov 20 16:37:56 heroku_app app/web.1: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/workers/base.py", line 122, in init_process
Nov 20 16:37:56 heroku_app app/web.1: self.load_wsgi()
Nov 20 16:37:56 heroku_app app/web.1: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/workers/base.py", line 132, in load_wsgi
Nov 20 16:37:56 heroku_app app/web.1: self.wsgi = self.app.wsgi()
Nov 20 16:37:56 heroku_app app/web.1: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
Nov 20 16:37:56 heroku_app app/web.1: self.callable = self.load()
Nov 20 16:37:56 heroku_app app/web.1: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
Nov 20 16:37:56 heroku_app app/web.1: return self.load_wsgiapp()
Nov 20 16:37:56 heroku_app app/web.1: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
Nov 20 16:37:56 heroku_app app/web.1: return util.import_app(self.app_uri)
Nov 20 16:37:56 heroku_app app/web.1: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/util.py", line 357, in import_app
Nov 20 16:37:56 heroku_app app/web.1: __import__(module)
Nov 20 16:37:56 heroku_app app/web.1: File "/app/config/wsgi.py", line 31, in <module>
Nov 20 16:37:56 heroku_app app/web.1: application = get_wsgi_application()
Nov 20 16:37:56 heroku_app app/web.1: File "/app/.heroku/python/lib/python2.7/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application
Nov 20 16:37:56 heroku_app app/web.1: django.setup()
Nov 20 16:37:56 heroku_app app/web.1: File "/app/.heroku/python/lib/python2.7/site-packages/django/__init__.py", line 17, in setup
Nov 20 16:37:56 heroku_app app/web.1: configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
Nov 20 16:37:56 heroku_app app/web.1: File "/app/.heroku/python/lib/python2.7/site-packages/django/conf/__init__.py", line 55, in __getattr__
Nov 20 16:37:56 heroku_app app/web.1: self._setup(name)
Nov 20 16:37:56 heroku_app app/web.1: File "/app/.heroku/python/lib/python2.7/site-packages/django/conf/__init__.py", line 43, in _setup
Nov 20 16:37:56 heroku_app app/web.1: self._wrapped = Settings(settings_module)
Nov 20 16:37:56 heroku_app app/web.1: File "/app/.heroku/python/lib/python2.7/site-packages/django/conf/__init__.py", line 99, in __init__
Nov 20 16:37:56 heroku_app app/web.1: mod = importlib.import_module(self.SETTINGS_MODULE)
Nov 20 16:37:56 heroku_app app/web.1: File "/app/.heroku/python/lib/python2.7/importlib/__init__.py", line 37, in import_module
Nov 20 16:37:56 heroku_app app/web.1: __import__(name)
Nov 20 16:37:56 heroku_app app/web.1: File "/app/config/settings/production.py", line 24, in <module>
Nov 20 16:37:56 heroku_app app/web.1: SECRET_KEY = env('DJANGO_SECRET_KEY')
Nov 20 16:37:56 heroku_app app/web.1: File "/app/.heroku/python/lib/python2.7/site-packages/environ/environ.py", line 111, in __call__
Nov 20 16:37:56 heroku_app app/web.1: return self.get_value(var, cast=cast, default=default, parse_default=parse_default)
Nov 20 16:37:56 heroku_app app/web.1: File "/app/.heroku/python/lib/python2.7/site-packages/environ/environ.py", line 253, in get_value
Nov 20 16:37:56 heroku_app app/web.1: raise ImproperlyConfigured(error_msg)
Nov 20 16:37:56 heroku_app app/web.1: ImproperlyConfigured: Set the DJANGO_SECRET_KEY environment variable
Nov 20 16:37:56 heroku_app app/web.1: [2016-11-20 05:37:56 +0000] [11] [INFO] Worker exiting (pid: 11)
Nov 20 16:37:56 heroku_app app/web.1: [2016-11-20 05:37:56 +0000] [10] [INFO] Worker exiting (pid: 10)
这是我的wsgi.py文件:
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings.production")
application = get_wsgi_application()
这是我的Procfile:
web: gunicorn config.wsgi:application --log-file -
我的production.py的前几行作为扩展设置文件:
from __future__ import absolute_import, unicode_literals
from boto.s3.connection import OrdinaryCallingFormat
from django.utils import six
from .common import * # noqa
# SECRET CONFIGURATION
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
# django-secure
# ------------------------------------------------------------------------------
INSTALLED_APPS += ('djangosecure', )
SECURITY_MIDDLEWARE = (
'djangosecure.middleware.SecurityMiddleware',
)
# Use Whitenoise to serve static files
# See: https://whitenoise.readthedocs.io/
WHITENOISE_MIDDLEWARE = (
'whitenoise.middleware.WhiteNoiseMiddleware',
)
答案 0 :(得分:0)
我又得到了自己的答案。
问题原因是Heroku中的“Config Var”缺少Django_Secret_Key // settings /.
解决方案是:
- echo .env >> .gitignore
- 编辑本地.env文件中可能需要的所有安全信息
- 确保Heroku上没有配置变量有空值,否则下一步不能覆盖当前空白。
- 在Heroku CLI中:heroku config:push
尝试的解决方案: 使用Heroku API。但只有通过CURL命令才能手动使用它。太痛苦了。也许我可以设计一些接口来自动化CURL命令输入过程或发送RESTful配置命令。