As per https://12factor.net/ Use environs/python-dotenv for reading/parsing variablesmaster
							parent
							
								
									72b224786f
								
							
						
					
					
						commit
						973bcd96cb
					
				| @ -0,0 +1,5 @@ | ||||
| # Environment variable overrides for local development | ||||
| FLASK_APP=autoapp.py | ||||
| FLASK_ENV=development | ||||
| DATABASE_URL="sqlite:////tmp/dev.db" | ||||
| SECRET_KEY="not-so-secret" | ||||
| @ -1,10 +1,5 @@ | ||||
| # -*- coding: utf-8 -*- | ||||
| """Create an application instance.""" | ||||
| from flask.helpers import get_debug_flag | ||||
| 
 | ||||
| from {{cookiecutter.app_name}}.app import create_app | ||||
| from {{cookiecutter.app_name}}.settings import DevConfig, ProdConfig | ||||
| 
 | ||||
| CONFIG = DevConfig if get_debug_flag() else ProdConfig | ||||
| 
 | ||||
| app = create_app(CONFIG) | ||||
| app = create_app() | ||||
|  | ||||
| @ -0,0 +1,11 @@ | ||||
| """Settings module for test app.""" | ||||
| ENV = 'development' | ||||
| TESTING = True | ||||
| SQLALCHEMY_DATABASE_URI = 'sqlite://' | ||||
| SECRET_KEY = 'not-so-secret-in-tests' | ||||
| BCRYPT_LOG_ROUNDS = 4  # For faster tests; needs at least 4 to avoid "ValueError: Invalid rounds" | ||||
| DEBUG_TB_ENABLED = False | ||||
| CACHE_TYPE = 'simple'  # Can be "memcached", "redis", etc. | ||||
| SQLALCHEMY_TRACK_MODIFICATIONS = False | ||||
| WEBPACK_MANIFEST_PATH = 'webpack/manifest.json' | ||||
| WTF_CSRF_ENABLED = False  # Allows form testing | ||||
| @ -1,19 +0,0 @@ | ||||
| # -*- coding: utf-8 -*- | ||||
| """Test configs.""" | ||||
| from {{cookiecutter.app_name}}.app import create_app | ||||
| from {{cookiecutter.app_name}}.settings import DevConfig, ProdConfig | ||||
| 
 | ||||
| 
 | ||||
| def test_production_config(): | ||||
|     """Production config.""" | ||||
|     app = create_app(ProdConfig) | ||||
|     assert app.config['ENV'] == 'prod' | ||||
|     assert app.config['DEBUG'] is False | ||||
|     assert app.config['DEBUG_TB_ENABLED'] is False | ||||
| 
 | ||||
| 
 | ||||
| def test_dev_config(): | ||||
|     """Development config.""" | ||||
|     app = create_app(DevConfig) | ||||
|     assert app.config['ENV'] == 'dev' | ||||
|     assert app.config['DEBUG'] is True | ||||
| @ -1,49 +1,23 @@ | ||||
| # -*- coding: utf-8 -*- | ||||
| """Application configuration.""" | ||||
| import os | ||||
| 
 | ||||
| 
 | ||||
| class Config(object): | ||||
|     """Base configuration.""" | ||||
| 
 | ||||
|     SECRET_KEY = os.environ.get('{{cookiecutter.app_name | upper}}_SECRET', 'secret-key')  # TODO: Change me | ||||
|     APP_DIR = os.path.abspath(os.path.dirname(__file__))  # This directory | ||||
|     PROJECT_ROOT = os.path.abspath(os.path.join(APP_DIR, os.pardir)) | ||||
|     BCRYPT_LOG_ROUNDS = 13 | ||||
|     DEBUG_TB_ENABLED = False  # Disable Debug toolbar | ||||
|     DEBUG_TB_INTERCEPT_REDIRECTS = False | ||||
|     CACHE_TYPE = 'simple'  # Can be "memcached", "redis", etc. | ||||
|     SQLALCHEMY_TRACK_MODIFICATIONS = False | ||||
|     WEBPACK_MANIFEST_PATH = 'webpack/manifest.json' | ||||
| 
 | ||||
| 
 | ||||
| class ProdConfig(Config): | ||||
|     """Production configuration.""" | ||||
| 
 | ||||
|     ENV = 'prod' | ||||
|     DEBUG = False | ||||
|     SQLALCHEMY_DATABASE_URI = 'postgresql://localhost/example'  # TODO: Change me | ||||
|     DEBUG_TB_ENABLED = False  # Disable Debug toolbar | ||||
| 
 | ||||
| 
 | ||||
| class DevConfig(Config): | ||||
|     """Development configuration.""" | ||||
| 
 | ||||
|     ENV = 'dev' | ||||
|     DEBUG = True | ||||
|     DB_NAME = 'dev.db' | ||||
|     # Put the db file in project root | ||||
|     DB_PATH = os.path.join(Config.PROJECT_ROOT, DB_NAME) | ||||
|     SQLALCHEMY_DATABASE_URI = 'sqlite:///{0}'.format(DB_PATH) | ||||
|     DEBUG_TB_ENABLED = True | ||||
|     CACHE_TYPE = 'simple'  # Can be "memcached", "redis", etc. | ||||
| 
 | ||||
| 
 | ||||
| class TestConfig(Config): | ||||
|     """Test configuration.""" | ||||
| 
 | ||||
|     TESTING = True | ||||
|     DEBUG = True | ||||
|     SQLALCHEMY_DATABASE_URI = 'sqlite://' | ||||
|     BCRYPT_LOG_ROUNDS = 4  # For faster tests; needs at least 4 to avoid "ValueError: Invalid rounds" | ||||
|     WTF_CSRF_ENABLED = False  # Allows form testing | ||||
| """Application configuration. | ||||
| 
 | ||||
| Most configuration is set via environment variables. | ||||
| 
 | ||||
| For local development, use a .env file to set | ||||
| environment variables. | ||||
| """ | ||||
| from environs import Env | ||||
| 
 | ||||
| env = Env() | ||||
| env.read_env() | ||||
| 
 | ||||
| ENV = env.str('FLASK_ENV', default='production') | ||||
| DEBUG = ENV == 'development' | ||||
| SQLALCHEMY_DATABASE_URI = env.str('DATABASE_URL') | ||||
| SECRET_KEY = env.str('SECRET_KEY') | ||||
| BCRYPT_LOG_ROUNDS = env.int('BCRYPT_LOG_ROUNDS', default=13) | ||||
| DEBUG_TB_ENABLED = DEBUG | ||||
| DEBUG_TB_INTERCEPT_REDIRECTS = False | ||||
| CACHE_TYPE = 'simple'  # Can be "memcached", "redis", etc. | ||||
| SQLALCHEMY_TRACK_MODIFICATIONS = False | ||||
| WEBPACK_MANIFEST_PATH = 'webpack/manifest.json' | ||||
|  | ||||
					Loading…
					
					
				
		Reference in new issue