-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
48 lines (38 loc) · 1.14 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
# External dependencies
import os
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_login import LoginManager
from flask_bcrypt import Bcrypt
from flask_mail import Mail
from flask_limiter import Limiter
# Internal dependencies
from config import DevelopmentConfig, ProductionConfig
# Instantiating Flask class
app = Flask(__name__)
limiter = Limiter(app, default_limits=["200 per day", "50 per hour"]) # new line
# Set the configuration based on the environment
if os.getenv('FLASK_ENV') == 'development':
app.config.from_object(DevelopmentConfig)
else:
app.config.from_object(ProductionConfig)
# Creating database
db = SQLAlchemy(app)
# Instantiating Bcrypt
bcrypt = Bcrypt(app)
# Flask Mail
mail = Mail(app)
# Login Manager
login_manager = LoginManager()
login_manager.init_app(app)
login_manager.login_view = 'login'
# # Importing routes at the end to avoid circular imports
from routes import *
with app.app_context():
try:
db.create_all()
print("Tables created.")
except Exception as e:
print("An error occurred while creating tables:", e)
if __name__ == '__main__':
app.run()