Guest User

Untitled

a guest
May 12th, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. app = Flask(__name__)
  2. app.config.from_object('yourapplication.Config')
  3.  
  4. class Config(object):
  5. DEBUG = True
  6. TESTING = False
  7. DB_USER = os.getenv("DB_USER", "db_user")
  8. DB_PASSWORD = os.getenv("DB_PASSWORD", "db_password")
  9. DB_HOST = os.getenv("DB_HOST", "localhost") # 127.0.0.1"
  10. DB_PORT = os.getenv("DB_PORT", "5555")
  11. DB_SCHEMA = "my_schema"
  12. DB_DATABASE_NAME = "my_database"
  13. SQLALCHEMY_DATABASE_URI = "postgresql://{}:{}@{}:{}/{}".format(
  14. DB_USER, DB_PASSWORD, DB_HOST, DB_PORT, DB_DATABASE_NAME)
  15. SQLALCHEMY_TRACK_MODIFICATIONS = False
  16.  
  17. my_flask_app cmd1 arg1 arg2
  18.  
  19. DEBUG=true DB_PORT=1234 my_flask_app cmd1 arg1 arg2
  20.  
  21. class BaseConfig:
  22. DEBUG = False
  23. TESTING = False
  24. SECRET_KEY = os.getenv('SECRET_KEY', 'a default secret key')
  25. ...
  26.  
  27. class DevelopmentConfig(BaseConfig):
  28. DEBUG = True
  29. ...
  30.  
  31.  
  32. class TestingConfig(BaseConfig):
  33. TESTING = True
  34. ...
  35.  
  36.  
  37. class ProductionConfig(BaseConfig):
  38. ...
  39.  
  40. app = Flask(__name__)
  41. app_settings = os.getenv(
  42. 'APP_SETTINGS',
  43. 'app.config.DevelopmentConfig'
  44. )
  45. app.config.from_object(app_settings)
  46.  
  47. > APP_SETTINGS=app.config.TestingConfig my_flask_app cmd1 arg1 arg2
Add Comment
Please, Sign In to add comment