isbn-sort/isbn_sort/__init__.py
2024-04-05 17:24:02 +02:00

25 lines
559 B
Python

from flask import Flask, redirect, g
import secrets
from .app import bp as app_bp
app = Flask(__name__)
app.config["DATABASE"] = "data/books.sqlite"
app.config["SECRET_KEY"] = secrets.token_hex()
app.register_blueprint(app_bp)
@app.route("/<path>")
def handle_redirect(path):
if not path.startswith("/app"):
return redirect("/app"+path, 301)
abort(404)
@app.after_request
def after_request(response):
"""Automatically close db after each request"""
if ('db' in g) and (g.db is not None):
g.db.close()
return response