Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- DATABASE = '/tmp/flaskr.db'
- DEBUG = True
- SECRET_KEY = 'dev key'
- USERNAME = 'admin'
- PASSWORD = 'default'
- # inherit config from Flask obj
- app = Flask(__name__)
- app.config.from_object(__name__)
- app.config.from_envvar('FLASK_SETTING', silent=True)
- # Activate sqlite DB connection using /tmp/flaskr.db
- def connect_db():
- return sqlite3.connect(app.config['DATABASE'])
- # execute script at cursor begining
- def init_db():
- with closing(connect_db()) as db:
- with app.open_resource('schema.sql') as f:
- db.cursor().executescript(f.read())
- db.commit()
- # run before request
- @app.before_request
- def before_request():
- g.db = connect_db()
- # process request
- @app.after_request
- def after_request(response):
- g.db.close()
- return response
- # post-process request
- def tearDown(exception):
- pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement