Environment can be switched via the MYFLASKAPP_ENV system variable.master
parent
48a6bd0c99
commit
7d37cb6254
@ -1,7 +1,13 @@ |
||||
# -*- coding: utf-8 -*- |
||||
import os |
||||
from flask import Flask |
||||
from flask.ext.sqlalchemy import SQLAlchemy |
||||
|
||||
app = Flask(__name__) |
||||
app.config.from_pyfile('settings.py') |
||||
# The environment variable, either 'prod' or 'dev' |
||||
env = os.environ.get("{{cookiecutter.repo_name | upper}}_ENV", "prod") |
||||
# Use the appropriate environment-specific settings |
||||
app.config.from_object('{{cookiecutter.repo_name}}.settings.{env}Config' |
||||
.format(env=env.capitalize())) |
||||
app.config['ENV'] = env |
||||
db = SQLAlchemy(app) |
||||
|
@ -1,10 +1,23 @@ |
||||
# -*- coding: utf-8 -*- |
||||
import os |
||||
|
||||
class Config(object): |
||||
SECRET_KEY = 'shhhh' |
||||
APP_DIR = os.path.abspath(os.path.dirname(__file__)) # This directory |
||||
PROJECT_ROOT = os.path.abspath(os.path.join(APP_DIR, os.pardir)) |
||||
|
||||
class ProdConfig(Config): |
||||
DEBUG = False |
||||
SQLALCHEMY_DATABASE_URI = 'postgresql://localhost/example' |
||||
SQLALCHEMY_ECHO = False |
||||
|
||||
class DevConfig(Config): |
||||
DEBUG = True |
||||
DB_NAME = "test.db" |
||||
DB_PATH = os.path.join(PROJECT_ROOT, DB_NAME) |
||||
# 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 = True |
||||
SECRET_KEY = 'shhhh' |
||||
SQLALCHEMY_ECHO = True |
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in new issue