-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
51 lines (34 loc) · 1.19 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
51
from flask import Flask
from extensions import db, login_manager
from routes import routes
from flask_limiter import Limiter
from flask_limiter.util import get_remote_address
def create_app():
app = Flask(__name__)
app.config['SECRET_KEY'] = 'your-secret-key-123'
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///inventory.db' #Initiation DB
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False #Signal limiting
# Initialize extensions
db.init_app(app)
login_manager.init_app(app)
# Configure login manager
login_manager.login_view = 'routes.login'
# Register blueprint
app.register_blueprint(routes)
# Create tables
with app.app_context():
db.create_all()
limiter = Limiter(
app=app,
key_func=get_remote_address,
default_limits=["200 per day", "50 per hour"]
)
# Apply to login route
limiter.limit("5 per minute")(app.view_functions['routes.login'])
def format_date(value, format='%d %b %Y'):
return value.strftime(format) if value else ''
app.jinja_env.filters['format_date'] = format_date
return app
if __name__ == '__main__':
app = create_app()
app.run(debug=False)