-
Notifications
You must be signed in to change notification settings - Fork 13
/
application.py
54 lines (43 loc) · 1.34 KB
/
application.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# external imports
import dash_bootstrap_components as dbc
import dash
from flask import Flask, request, current_app
from flask_login import LoginManager
import sqlalchemy
# local imports
from models.user import User
from utils.auth import protect_layouts
from utils.config import get_session, make_engine
def create_app():
server = Flask(__name__)
app = dash.Dash(
__name__,
server=server,
external_stylesheets=[
dbc.themes.LITERA,
"https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.css",
],
use_pages=True,
suppress_callback_exceptions=True,
title="Dash Auth Flow",
update_title=None,
)
# app.css.config.serve_locally = True
# app.scripts.config.serve_locally = True
# config
server.config.update(
SECRET_KEY="make this key random or hard to guess",
)
server.engine = make_engine()
# Setup the LoginManager for the server
login_manager = LoginManager()
login_manager.init_app(server)
login_manager.login_view = "/login"
# callback to reload the user object
@login_manager.user_loader
def load_user(user_id):
with get_session() as session:
return session.get(User, user_id)
return app, server
app, server = create_app()
protect_layouts(default=True)