heroku-python/flask-heroku

Setting fallback values for local development

yuvadm opened this issue · 1 comments

What would be the proper way to set fallback values in case DATABASE_URL (for example) is not set on a development environment?

Right now the proper way seems to be:

from os import environ
heroku = Heroku(app)
if 'DATABASE_URL' not in environ:
    app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/test.db'

Is there any way to get this fallback behavior from flask-heroku?

The development paradigm this is supporting requires that "deploys" be distinguished outside the codebase - your dev settings shouldn't be in a file at all, but in the environment variables of your development machine. See Factor III.

I do this right now by keeping a python file that lets me quickly set the proper env vars from the terminal, in the parent directory of the repo. My file structure looks like this:

  • dev contains all my repos, for all projects I'm working on
  • myproject-vars-dev.py sets up the env vars for my dev
  • myproject-vars-[branch].py contains special env vars for a branch that is different
  • myproject\
    • runserver.py runs Flask's dev server or production server, based on env var
    • myproject\
      • __init__.py