我正在尝试将我的 Django 项目部署到 Heroku,但有关我的 SECRET_KEY 的错误不断出现
I am trying to deploy my Django project to Heroku but an error regarding my SECRET_KEY keeps appearing
我正在将一个电子商务项目部署到 Heroku,似乎 运行 经常出现问题和错误。
我最近的错误围绕着下面的回溯:
2019-11-11T13:35:34.080363+00:00 heroku[web.1]: State changed from crashed to starting
2019-11-11T13:35:40.020789+00:00 heroku[web.1]: Starting process with command `gunicorn fancyfetish.wsgi:application --preload --workers 1`
2019-11-11T13:35:42.589255+00:00 heroku[web.1]: State changed from starting to crashed
2019-11-11T13:35:42.460008+00:00 app[web.1]: Traceback (most recent call last):
2019-11-11T13:35:42.460049+00:00 app[web.1]: File "/app/.heroku/python/bin/gunicorn", line 11, in <module>
2019-11-11T13:35:42.460136+00:00 app[web.1]: sys.exit(run())
2019-11-11T13:35:42.460148+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 58, in run
2019-11-11T13:35:42.460262+00:00 app[web.1]: WSGIApplication("%(prog)s [OPTIONS] [APP_MODULE]").run()
2019-11-11T13:35:42.460273+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/base.py", line 219, in run
2019-11-11T13:35:42.460434+00:00 app[web.1]: super().run()
2019-11-11T13:35:42.460438+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/base.py", line 72, in run
2019-11-11T13:35:42.460565+00:00 app[web.1]: Arbiter(self).run()
2019-11-11T13:35:42.460571+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 58, in __init__
2019-11-11T13:35:42.460689+00:00 app[web.1]: self.setup(app)
2019-11-11T13:35:42.460692+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 118, in setup
2019-11-11T13:35:42.460823+00:00 app[web.1]: self.app.wsgi()
2019-11-11T13:35:42.460827+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/base.py", line 67, in wsgi
2019-11-11T13:35:42.460978+00:00 app[web.1]: self.callable = self.load()
2019-11-11T13:35:42.460981+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 49, in load
2019-11-11T13:35:42.461083+00:00 app[web.1]: return self.load_wsgiapp()
2019-11-11T13:35:42.461087+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 39, in load_wsgiapp
2019-11-11T13:35:42.461204+00:00 app[web.1]: return util.import_app(self.app_uri)
2019-11-11T13:35:42.461207+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/util.py", line 331, in import_app
2019-11-11T13:35:42.461388+00:00 app[web.1]: mod = importlib.import_module(module)
2019-11-11T13:35:42.461392+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/importlib/__init__.py", line 126, in import_module
2019-11-11T13:35:42.461529+00:00 app[web.1]: return _bootstrap._gcd_import(name[level:], package, level)
2019-11-11T13:35:42.461542+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 994, in _gcd_import
2019-11-11T13:35:42.461664+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 971, in _find_and_load
2019-11-11T13:35:42.461737+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
2019-11-11T13:35:42.461813+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
2019-11-11T13:35:42.461888+00:00 app[web.1]: File "<frozen importlib._bootstrap_external>", line 678, in exec_module
2019-11-11T13:35:42.461983+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
2019-11-11T13:35:42.462061+00:00 app[web.1]: File "/app/fancyfetish/wsgi.py", line 17, in <module>
2019-11-11T13:35:42.462171+00:00 app[web.1]: application = get_wsgi_application()
2019-11-11T13:35:42.462176+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
2019-11-11T13:35:42.462279+00:00 app[web.1]: django.setup(set_prefix=False)
2019-11-11T13:35:42.462298+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/django/__init__.py", line 19, in setup
2019-11-11T13:35:42.462381+00:00 app[web.1]: configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
2019-11-11T13:35:42.462385+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/django/conf/__init__.py", line 79, in __getattr__
2019-11-11T13:35:42.462516+00:00 app[web.1]: self._setup(name)
2019-11-11T13:35:42.462519+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/django/conf/__init__.py", line 66, in _setup
2019-11-11T13:35:42.462637+00:00 app[web.1]: self._wrapped = Settings(settings_module)
2019-11-11T13:35:42.462639+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/django/conf/__init__.py", line 176, in __init__
2019-11-11T13:35:42.462783+00:00 app[web.1]: raise ImproperlyConfigured("The SECRET_KEY setting must not be empty.")
2019-11-11T13:35:42.462808+00:00 app[web.1]: django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty.
2019-11-11T13:35:42.575764+00:00 heroku[web.1]: Process exited with status 1
2019-11-11T13:35:47.000000+00:00 app[api]: Build succeeded
2019-11-11T13:36:25.358883+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=fancyfetish.herokuapp.com request_id=4f0e5e77-53c9-443a-8647-c5b88a01ae17 fwd="81.100.164.113" dyno= connect= service= status=503 bytes= protocol=https
2019-11-11T13:36:25.563374+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=fancyfetish.herokuapp.com request_id=3828cca1-593c-4785-9c82-6b614c233dea fwd="81.100.164.113" dyno= connect= service= status=503 bytes= protocol=https
我在设置目录下得到了三个设置文件,概述如下:
|____settings
| |______init__.py
| |____development.py
| |______pycache__
| | |____production.cpython-37.pyc
| | |____base.cpython-37.pyc
| | |____development.cpython-37.pyc
| | |______init__.cpython-37.pyc
| |____base.py
| |____production.py
|______init__.py
|______pycache__
| |____settings.cpython-37.pyc
| |____wsgi.cpython-37.pyc
| |____urls.cpython-37.pyc
| |______init__.cpython-37.pyc
|____urls.py
|____wsgi.py
我的所有三个设置文件(base.py、development.py 和 production.py)都定义了 SECRET_KEY,所以我不确定为什么一直出现此错误。
SECRET_KEY是随机生成的。这与gunicorn有关吗?
我的 wsgi 文件如下所示:
import os
from django.core.wsgi import get_wsgi_application
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'fancyfetish.settings')
application = get_wsgi_application()
(我不确定是否需要从 django.core.wsgi 导入,但这似乎是其他人的解决方案,对我不起作用)
我的 Procfile 如下所示:
web: gunicorn fancyfetish.wsgi:application --preload --workers 1
我的 requirements.txt 文件如下所示:
beautifulsoup4==4.8.1
Django==2.2.6
django-appconf==1.0.3
django-bootstrap4==1.0.1
django-compressor==2.3
django-libsass==0.7
django-sass-processor==0.7.4
gunicorn==20.0.0
libsass==0.19.3
mysql-connector-python==8.0.18
Pillow==6.2.1
protobuf==3.10.0
pytz==2019.3
rcssmin==1.0.6
rjsmin==1.1.0
six==1.12.0
soupsieve==1.9.5
sqlparse==0.3.0
有谁能看出我做错了什么?是不是版本之间的兼容性问题?
尝试更改 wsgi 文件中的这一行:
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'fancyfetish.settings')
为此:
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'fancyfetish.settings.development') # or .production
我正在将一个电子商务项目部署到 Heroku,似乎 运行 经常出现问题和错误。
我最近的错误围绕着下面的回溯:
2019-11-11T13:35:34.080363+00:00 heroku[web.1]: State changed from crashed to starting
2019-11-11T13:35:40.020789+00:00 heroku[web.1]: Starting process with command `gunicorn fancyfetish.wsgi:application --preload --workers 1`
2019-11-11T13:35:42.589255+00:00 heroku[web.1]: State changed from starting to crashed
2019-11-11T13:35:42.460008+00:00 app[web.1]: Traceback (most recent call last):
2019-11-11T13:35:42.460049+00:00 app[web.1]: File "/app/.heroku/python/bin/gunicorn", line 11, in <module>
2019-11-11T13:35:42.460136+00:00 app[web.1]: sys.exit(run())
2019-11-11T13:35:42.460148+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 58, in run
2019-11-11T13:35:42.460262+00:00 app[web.1]: WSGIApplication("%(prog)s [OPTIONS] [APP_MODULE]").run()
2019-11-11T13:35:42.460273+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/base.py", line 219, in run
2019-11-11T13:35:42.460434+00:00 app[web.1]: super().run()
2019-11-11T13:35:42.460438+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/base.py", line 72, in run
2019-11-11T13:35:42.460565+00:00 app[web.1]: Arbiter(self).run()
2019-11-11T13:35:42.460571+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 58, in __init__
2019-11-11T13:35:42.460689+00:00 app[web.1]: self.setup(app)
2019-11-11T13:35:42.460692+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 118, in setup
2019-11-11T13:35:42.460823+00:00 app[web.1]: self.app.wsgi()
2019-11-11T13:35:42.460827+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/base.py", line 67, in wsgi
2019-11-11T13:35:42.460978+00:00 app[web.1]: self.callable = self.load()
2019-11-11T13:35:42.460981+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 49, in load
2019-11-11T13:35:42.461083+00:00 app[web.1]: return self.load_wsgiapp()
2019-11-11T13:35:42.461087+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 39, in load_wsgiapp
2019-11-11T13:35:42.461204+00:00 app[web.1]: return util.import_app(self.app_uri)
2019-11-11T13:35:42.461207+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/util.py", line 331, in import_app
2019-11-11T13:35:42.461388+00:00 app[web.1]: mod = importlib.import_module(module)
2019-11-11T13:35:42.461392+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/importlib/__init__.py", line 126, in import_module
2019-11-11T13:35:42.461529+00:00 app[web.1]: return _bootstrap._gcd_import(name[level:], package, level)
2019-11-11T13:35:42.461542+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 994, in _gcd_import
2019-11-11T13:35:42.461664+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 971, in _find_and_load
2019-11-11T13:35:42.461737+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
2019-11-11T13:35:42.461813+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
2019-11-11T13:35:42.461888+00:00 app[web.1]: File "<frozen importlib._bootstrap_external>", line 678, in exec_module
2019-11-11T13:35:42.461983+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
2019-11-11T13:35:42.462061+00:00 app[web.1]: File "/app/fancyfetish/wsgi.py", line 17, in <module>
2019-11-11T13:35:42.462171+00:00 app[web.1]: application = get_wsgi_application()
2019-11-11T13:35:42.462176+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
2019-11-11T13:35:42.462279+00:00 app[web.1]: django.setup(set_prefix=False)
2019-11-11T13:35:42.462298+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/django/__init__.py", line 19, in setup
2019-11-11T13:35:42.462381+00:00 app[web.1]: configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
2019-11-11T13:35:42.462385+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/django/conf/__init__.py", line 79, in __getattr__
2019-11-11T13:35:42.462516+00:00 app[web.1]: self._setup(name)
2019-11-11T13:35:42.462519+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/django/conf/__init__.py", line 66, in _setup
2019-11-11T13:35:42.462637+00:00 app[web.1]: self._wrapped = Settings(settings_module)
2019-11-11T13:35:42.462639+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/django/conf/__init__.py", line 176, in __init__
2019-11-11T13:35:42.462783+00:00 app[web.1]: raise ImproperlyConfigured("The SECRET_KEY setting must not be empty.")
2019-11-11T13:35:42.462808+00:00 app[web.1]: django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty.
2019-11-11T13:35:42.575764+00:00 heroku[web.1]: Process exited with status 1
2019-11-11T13:35:47.000000+00:00 app[api]: Build succeeded
2019-11-11T13:36:25.358883+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=fancyfetish.herokuapp.com request_id=4f0e5e77-53c9-443a-8647-c5b88a01ae17 fwd="81.100.164.113" dyno= connect= service= status=503 bytes= protocol=https
2019-11-11T13:36:25.563374+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=fancyfetish.herokuapp.com request_id=3828cca1-593c-4785-9c82-6b614c233dea fwd="81.100.164.113" dyno= connect= service= status=503 bytes= protocol=https
我在设置目录下得到了三个设置文件,概述如下:
|____settings
| |______init__.py
| |____development.py
| |______pycache__
| | |____production.cpython-37.pyc
| | |____base.cpython-37.pyc
| | |____development.cpython-37.pyc
| | |______init__.cpython-37.pyc
| |____base.py
| |____production.py
|______init__.py
|______pycache__
| |____settings.cpython-37.pyc
| |____wsgi.cpython-37.pyc
| |____urls.cpython-37.pyc
| |______init__.cpython-37.pyc
|____urls.py
|____wsgi.py
我的所有三个设置文件(base.py、development.py 和 production.py)都定义了 SECRET_KEY,所以我不确定为什么一直出现此错误。
SECRET_KEY是随机生成的。这与gunicorn有关吗?
我的 wsgi 文件如下所示:
import os
from django.core.wsgi import get_wsgi_application
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'fancyfetish.settings')
application = get_wsgi_application()
(我不确定是否需要从 django.core.wsgi 导入,但这似乎是其他人的解决方案,对我不起作用)
我的 Procfile 如下所示:
web: gunicorn fancyfetish.wsgi:application --preload --workers 1
我的 requirements.txt 文件如下所示:
beautifulsoup4==4.8.1
Django==2.2.6
django-appconf==1.0.3
django-bootstrap4==1.0.1
django-compressor==2.3
django-libsass==0.7
django-sass-processor==0.7.4
gunicorn==20.0.0
libsass==0.19.3
mysql-connector-python==8.0.18
Pillow==6.2.1
protobuf==3.10.0
pytz==2019.3
rcssmin==1.0.6
rjsmin==1.1.0
six==1.12.0
soupsieve==1.9.5
sqlparse==0.3.0
有谁能看出我做错了什么?是不是版本之间的兼容性问题?
尝试更改 wsgi 文件中的这一行:
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'fancyfetish.settings')
为此:
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'fancyfetish.settings.development') # or .production