使用未跟踪的.env文件部署到Heroku [英] Deploying to Heroku with untracked .env file

查看:66
本文介绍了使用未跟踪的.env文件部署到Heroku的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法在Heroku上部署Django应用程序.

I am having trouble deploying my Django application on Heroku.

发生问题是因为我正在使用 python-decouple .我正在使用它,以免暴露我的 API_KEYS .

The problem occurs because I am using the python-decouple library. I am using it so as not to expose my API_KEYS.

这是我得到的错误:

  File "/app/weather/settings.py", line 20, in <module>
    API_KEY = config('API_KEY')
  File "/app/.heroku/python/lib/python3.6/site-packages/decouple.py", line 197, in __call__
     return self.config(*args, **kwargs)
  File "/app/.heroku/python/lib/python3.6/site-packages/decouple.py", line 85, in __call__
    return self.get(*args, **kwargs)
  File "/app/.heroku/python/lib/python3.6/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: API_KEY not found. Declare it as envvar or define a default value.

我已将所有变量存储在 BASE_DIR +'/.env'文件中,并将此文件添加到我的 .gitignore 文件中.

I have stored all the variables in BASE_DIR + '/.env' file and added this file to my .gitignore file.

该问题的解决方案是什么?

What is the solution to this problem?

推荐答案

您将无法从Heroku上未跟踪的文件中加载设置.它的文件系统是短暂的;下次您的dyno重新启动时,您手动添加的所有内容都会丢失.此经常发生.

You won't be able to load settings from files that aren't tracked on Heroku. Its filesystem is ephemeral; anything you add to it manually will be lost the next time your dyno restarts. This happens frequently.

"Heroku方式"是将设置放入环境变量.环境变量将对所有测功机可用,并具有两个主要优点:

The "Heroku way" is to put your settings in environment variables. Environment variables will be available to all dynos, and have two major benefits:

  • 您的设置不会显示在您的代码存储库中
  • 您可以更改环境变量而无需更改代码

很高兴地, python-自3.0版起,decouple 就尊重环境变量.您应该能够为所有设置添加环境变量,然后成功部署.(我以前没有使用过该库,但是,如果在环境中找到了所有设置,则好像不需要 .env 文件.)

Happily, python-decouple respects environment variables since version 3.0. You should be able to add environment variables for all of your settings and then deploy successfully. (I haven't used that library before, but it looks like you don't need an .env file if all of your settings are found in the environment.)

这篇关于使用未跟踪的.env文件部署到Heroku的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆