Environment can be switched via the MYFLASKAPP_ENV system variable.master
parent
48a6bd0c99
commit
7d37cb6254
@ -1,7 +1,13 @@ |
|||||||
# -*- coding: utf-8 -*- |
# -*- coding: utf-8 -*- |
||||||
|
import os |
||||||
from flask import Flask |
from flask import Flask |
||||||
from flask.ext.sqlalchemy import SQLAlchemy |
from flask.ext.sqlalchemy import SQLAlchemy |
||||||
|
|
||||||
app = Flask(__name__) |
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) |
db = SQLAlchemy(app) |
||||||
|
@ -1,10 +1,23 @@ |
|||||||
# -*- coding: utf-8 -*- |
# -*- coding: utf-8 -*- |
||||||
import os |
import os |
||||||
|
|
||||||
APP_DIR = os.path.abspath(os.path.dirname(__file__)) # This directory |
class Config(object): |
||||||
PROJECT_ROOT = os.path.abspath(os.path.join(APP_DIR, os.pardir)) |
SECRET_KEY = 'shhhh' |
||||||
DB_NAME = "test.db" |
APP_DIR = os.path.abspath(os.path.dirname(__file__)) # This directory |
||||||
DB_PATH = os.path.join(PROJECT_ROOT, DB_NAME) |
PROJECT_ROOT = os.path.abspath(os.path.join(APP_DIR, os.pardir)) |
||||||
SQLALCHEMY_DATABASE_URI = "sqlite:///{0}".format(DB_PATH) |
|
||||||
DEBUG = True |
class ProdConfig(Config): |
||||||
SECRET_KEY = 'shhhh' |
DEBUG = False |
||||||
|
SQLALCHEMY_DATABASE_URI = 'postgresql://localhost/example' |
||||||
|
SQLALCHEMY_ECHO = False |
||||||
|
|
||||||
|
class DevConfig(Config): |
||||||
|
DEBUG = True |
||||||
|
DB_NAME = "test.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) |
||||||
|
SQLALCHEMY_ECHO = True |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in new issue