Initial commit
This commit is contained in:
44
app.py
Normal file
44
app.py
Normal file
@@ -0,0 +1,44 @@
|
||||
import os
|
||||
import sqlite3
|
||||
|
||||
from flask import Flask, g, redirect, url_for
|
||||
|
||||
from config import DB_PATH, SECRET_KEY
|
||||
from database.init_db import init_db
|
||||
|
||||
|
||||
def create_app():
|
||||
app = Flask(__name__)
|
||||
app.secret_key = SECRET_KEY
|
||||
app.config["MAX_CONTENT_LENGTH"] = 16 * 1024 * 1024
|
||||
|
||||
os.makedirs(os.path.dirname(DB_PATH), exist_ok=True)
|
||||
|
||||
with sqlite3.connect(DB_PATH) as conn:
|
||||
init_db(conn)
|
||||
|
||||
@app.before_request
|
||||
def open_db():
|
||||
if "db" not in g:
|
||||
g.db = sqlite3.connect(DB_PATH)
|
||||
g.db.row_factory = sqlite3.Row
|
||||
|
||||
@app.teardown_appcontext
|
||||
def close_db(exception):
|
||||
db = g.pop("db", None)
|
||||
if db is not None:
|
||||
db.close()
|
||||
|
||||
from routes import bp
|
||||
|
||||
app.register_blueprint(bp)
|
||||
|
||||
@app.route("/")
|
||||
def index():
|
||||
return redirect(url_for("main.documents_1c"))
|
||||
|
||||
return app
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
create_app().run(debug=True, host="0.0.0.0", port=5000)
|
||||
Reference in New Issue
Block a user