diff options
| author | Guillaume Horel <guillaume.horel@gmail.com> | 2013-12-01 19:05:00 -0500 |
|---|---|---|
| committer | Guillaume Horel <guillaume.horel@gmail.com> | 2013-12-01 19:05:00 -0500 |
| commit | 85eada5021e197da4fe6fb3df18a324435c7fac7 (patch) | |
| tree | 31eafe3e734027c4e5dc31ae041dc41f94072eb9 /famille.py | |
| parent | 29fd9243954966d4a1c86e2ab3bc4ebf4c16bef2 (diff) | |
| download | famille-flask-85eada5021e197da4fe6fb3df18a324435c7fac7.tar.gz | |
one more try
Diffstat (limited to 'famille.py')
| -rw-r--r-- | famille.py | 12 |
1 files changed, 7 insertions, 5 deletions
@@ -81,15 +81,17 @@ def connect_db(): return conn def get_db(): - if not hasattr(g, 'sqlite_db'): - g.sqlite_db = connect_db() - return g.sqlite_db + db = getattr(g, 'sqlite_db', None) + if db is None: + db = g.sqlite_db = connect_db() + return db @app.teardown_appcontext def close_db(error): """Closes the database again at the end of the request.""" - if hasattr(g, 'sqlite_db'): - g.sqlite_db.close() + db = getattr(g, 'sqlite_db', None) + if db: + db.close() def login_required(f): @wraps(f) |
