-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
50 lines (37 loc) · 1.39 KB
/
app.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
# app.py
"""
This is the app.py module, responsible for initializing the Flask application.
Major functions include:
Creating a Flask application instance (app)
Initializing the LoginManager, which handles user sessions
Setting up CORS in the app, which ensures the app securely handles requests from different origins
Establishing database connection via SQLAlchemy
Setting up a secret key for encryption
Initializing Bcrypt, which handles password hashing
Connecting the application with models using SQLAlchemy's init_app() function
Defining routes within the application
This module is primarily used to run the Flask application.
The command app.run(debug=True) runs the application in a local development environment, with
debugging mode turned on.
"""
from flask import Flask
from flask_bcrypt import Bcrypt
from flask_cors import CORS
from features import models
from features import routes
from features.login_manager import login_manager # Add this line
app = Flask(__name__)
# Initiate login manager
login_manager.init_app(app)
login_manager.login_view = 'login'
CORS(app)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///database.db'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True
# Change the key!!!
app.config['SECRET_KEY'] = 'thisisasecretkey'
bcrypt = Bcrypt(app)
models.db.init_app(app)
# Define routes
routes.define_routes(app, bcrypt)
if __name__ == "__main__":
app.run(debug=True)