flask app从py文件加载配置文件(flask 34)

2019-08-13 14:46:03 浏览数 (1)

settings.py

import os import sys

from app import app

SQLite URI compatible

WIN = sys.platform.startswith('win') if WIN: prefix = 'sqlite:///' else: prefix = 'sqlite:////'

dev_db = prefix os.path.join(os.path.dirname(app.root_path), 'data.db')

SECRET_KEY = os.getenv('SECRET_KEY', 'secret string') SQLALCHEMY_TRACK_MODIFICATIONS = False SQLALCHEMY_DATABASE_URI = os.getenv('DATABASE_URI', dev_db)

app.py

app = Flask('sayhello') app.config.from_pyfile('settings.py')

0 人点赞