14

I need to programatically determine if my app is running in development or not, so that I can provide sandbox values for a variety of constants and methods.

Something like:

if app.development: # Live mode
  FREEBASE_USER = "spam123"
  FREEBASE_PSWD = "eggs123"
  FREEBASE = freebase

else: # Sandbox mode
  FREEBASE_USER = "spam"
  FREEBASE_PSWD = "eggs"
  FREEBASE = freebase.sandbox
Will Curran
  • 6,959
  • 15
  • 59
  • 92

1 Answers1

36
import os

DEV = os.environ['SERVER_SOFTWARE'].startswith('Development')
Drew Sears
  • 12,812
  • 1
  • 32
  • 41
  • os.environ['SERVER_SOFTWARE'] was missing in our os.environ dictionary (Mac), but os.environ['PYCHARM_HOSTED'] was present and == "1" which was good enough to recognize our dev environment. – Praxiteles Feb 16 '16 at 23:40
  • How can we make this variable to be available app-wide? – hyang123 Jun 07 '18 at 21:11