Heroku Database Settings Injection - How do I setup my dev django database?

前端 未结 5 1799
孤城傲影
孤城傲影 2021-01-30 04:32

I\'m trying to get my local dev django app to work after following these instructions on adding env database settings.

https://devcenter.heroku.com/articles/django-injec

5条回答
  •  鱼传尺愫
    2021-01-30 04:55

    Just set an environment variable on your operating system and check weither or not it's set. For instance, with a UNIX system:

    # In ~/.bash_profile
    export LOCAL_DEV=true
    
    # In settings.py
    import dj_database_url
    DATABASES = {'default': dj_database_url.config(default='postgres://localhost')}
    
    if bool(os.environ.get('LOCAL_DEV', False)):
        # Override DATABASES['default'] with your local database configuration
    

    Also, if you need to set an environment variable on your heroku space:

    heroku config:add MY_VAR='my_value'
    

提交回复
热议问题