Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2017
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.41 KB | None | 0 0
  1. DATABASE = '/tmp/flaskr.db'
  2. DEBUG = True
  3. SECRET_KEY = 'dev key'
  4. USERNAME = 'admin'
  5. PASSWORD = 'default'
  6.  
  7. # inherit config from Flask obj                                                                                              
  8. app = Flask(__name__)
  9. app.config.from_object(__name__)
  10. app.config.from_envvar('FLASK_SETTING', silent=True)
  11.  
  12. # Activate sqlite DB connection using /tmp/flaskr.db                                                                          
  13. def connect_db():
  14.     return sqlite3.connect(app.config['DATABASE'])
  15.  
  16. # execute script at cursor begining                                                                                          
  17. def init_db():
  18.     with closing(connect_db()) as db:
  19.         with app.open_resource('schema.sql') as f:
  20.             db.cursor().executescript(f.read())
  21.         db.commit()
  22.  
  23. # run before request                                                                                                          
  24. @app.before_request
  25. def before_request():
  26.     g.db = connect_db()
  27.  
  28. # process request                                                                                                            
  29. @app.after_request
  30. def after_request(response):
  31.     g.db.close()
  32.     return response
  33.  
  34. # post-process request                                                                                                        
  35. def tearDown(exception):
  36.     pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement