From 7054b67a4b19cd389cfaab5b0f564ba5c27f64e3 Mon Sep 17 00:00:00 2001 From: Tharre Date: Sun, 20 Aug 2017 12:27:33 +0200 Subject: Create db in init_db() instead of __main__ If the application is run by i.e. uwsgi then __main__ is never called, and subsequently the database is not being created. --- app.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app.py b/app.py index ca9a7c8..410ad0d 100755 --- a/app.py +++ b/app.py @@ -15,6 +15,9 @@ DATABASE = 'db.sqlite3' cache = SimpleCache() def init_db(): + if not os.path.isfile(DATABASE): + init_db() + with app.app_context(): db = get_db() with app.open_resource('schema.sql', mode='r') as f: @@ -130,7 +133,4 @@ def handle_404(error): return make_response(jsonify({'error': 'Not found'}), 404) if __name__ == '__main__': - if not os.path.isfile(DATABASE): - init_db() - app.run(host='0.0.0.0', debug=True) -- cgit v1.2.3-70-g09d2