Issue
I have a Flask application that uses different configuration files for development and production environments. The relevant piece of code is this:
app.config.from_object('config.dev')
app.config.from_envvar('SPOTPIX_SETTINGS', silent=True)
When I'm developing in my local server, the configurations are taken from config.dev, but when I push the code to Heroku, I would like to set the SPOTPIX_SETTINGS
environment variable to point to the 'config.prod' file. This can be done in the Heroku command line client like so:
heroku config:set SPOTPIX_SETTINGS=
However, I have no clue what should I write to the right of the equals sign, as I can't assign the absolute path of the production configuration file to the environment variable, because this is not the same in Heroku as it is in my development machine.
Solution
You should use an environment variable to check if you are in a dev or in Heroku environment.
heroku config:set IS_HEROKU=True
Then in your file
import os
is_prod = os.environ.get('IS_HEROKU', None)
if is_prod:
#here goes all your heroku config
Answered By - levi
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.