-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path__init__.py
56 lines (36 loc) · 1.4 KB
/
__init__.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
55
56
'''
This file is used for base configurtion of the Flask app which runs the forntend service.
Creates the base flask app,
1. integrated with SQL-Alchemy for Database integration
2. flask-login app for handling user login sessions in the init_app
3. registers all the blueprints that consists routes to various services and pages.
'''
from flask import Flask
from flask_login import LoginManager
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate
# init SQLAlchemy so we can use it later in our models
db = SQLAlchemy()
login_manager = LoginManager()
def create_app():
app = Flask(__name__)
migrate = Migrate(app, db)
app.config['SECRET_KEY'] = '9OLWxND4o83j4K4iuopO'
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///database.db'
db.init_app(app)
login_manager.init_app(app)
login_manager.login_view = "auth.login"
# blueprint for auth routes in our app
from .auth import auth as auth_blueprint
app.register_blueprint(auth_blueprint)
# blueprint for non-auth parts of app
from .main import main as main_blueprint
app.register_blueprint(main_blueprint)
# blueprint for non-auth parts of app
from .services import services as services_blueprint
app.register_blueprint(services_blueprint)
from .models_db import User
@login_manager.user_loader
def load_user(id):
return User.query.get(int(id))
return app