2

我正在尝试在本地运行我的 Heroku 应用程序并按照此处的说明进行操作。

当我尝试运行以下命令时:

python manage.py collectstatic

我有这个错误:

Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "C:\Python36-32\lib\site-packages\django\core\management\__init__.py", line 371, in execute_from_command_line
utility.execute()
File "C:\Python36-32\lib\site-packages\django\core\management\__init__.py", line 317, in execute
settings.INSTALLED_APPS
File "C:\Python36-32\lib\site-packages\django\conf\__init__.py", line 56, in __getattr__
self._setup(name)
File "C:\Python36-32\lib\site-packages\django\conf\__init__.py", line 43, in _setup
self._wrapped = Settings(settings_module)
File "C:\Python36-32\lib\site-packages\django\conf\__init__.py", line 106, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "C:\Python36-32\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:\Users\robina\Ubelt-Dorm\ph_dorms\settings.py", line 25, in <module>
SECRET_KEY = config('SECRET_KEY')
File "C:\Python36-32\lib\site-packages\decouple.py", line 197, in __call__
return self.config(*args, **kwargs)
File "C:\Python36-32\lib\site-packages\decouple.py", line 85, in __call__
return self.get(*args, **kwargs)
File "C:\Python36-32\lib\site-packages\decouple.py", line 70, in get
raise UndefinedValueError('{} not found. Declare it as envvar or define a default value.'.format(option))
decouple.UndefinedValueError: SECRET_KEY not found. Declare it as envvar or define a default value.

SECRET_KEY 已在 Heroku 上声明为配置变量。

在此处输入图像描述

我已经联系了 Heroku,但仍然没有回复,所以也许这里的某个人可以在他们面前找到解决此错误的方法。

我想使用与 web 相同的版本在本地运行此应用程序,因此添加SECRET_KEYsettings.py我来说不是一条路线。

settings.py的配置是这样的:

from decouple import config
SECRET_KEY = config('SECRET_KEY')
4

2 回答 2

4

您可以通过将本地环境变量添加到.env文件中来设置本地环境变量,然后通过heroku local. 这会将所有NAME=value行从.envenv vars 转换为然后可用于您的应用程序。然后您可以添加.env到您的.gitignore,因为这仅在您的本地计算机上是必需的。有关更多详细信息,请参阅https://devcenter.heroku.com/articles/heroku-local#set-up-your-local-environment-variables

于 2018-03-11T09:29:20.093 回答
3

您可以使用 Heroku 的命令行工具设置环境变量,如下所示:

heroku config:set SECRET_KEY='Your secret key'
于 2018-03-11T21:43:36.890 回答