Question

I have some config vars set on Heroku as described here: https://devcenter.heroku.com/articles/config-vars. When I run:

heroku config

I see the config var in the list:

COMPRESS_OFFLINE:                  True

and I can run

heroku config:get COMPRESS_OFFLINE

and I get:

True

In my Django settings.py, I have:

import os
COMPRESS_OFFLINE = os.environ['COMPRESS_OFFLINE']

This is how the article linked above tells you to access Heroku config variables in Django. I have this config var set in my local .env file, and I can run foreman locally. But, when I deploy to Heroku, I get this error during deploy:

KeyError: 'COMPRESS_OFFLINE'
!     Push rejected, failed to compile Python app

I have the feeling I'm missing something painfully obvious, any suggestions?

Was it helpful?

Solution

I got an answer back from Heroku support that environment variables are not available during slug compilation by default. But, there is an experimental feature called user-env-compile that will make them available: http://devcenter.heroku.com/articles/labs-user-env-compile

I didn't need this, though. I thought that because it couldn't find them during compile that it wouldn't be able to find them at all. But, I found that they are available after compile. So, I just updated settings.py to have:

COMPRESS_OFFLINE = os.environ.get('COMPRESS_OFFLINE', True)

So that it defaults to True during compile when the environment variable is not available.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top