forked from kottik-mypp/flask_app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
49 lines (35 loc) · 1.18 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
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from os import path
from flask_login import LoginManager
from flask_bcrypt import Bcrypt
db = SQLAlchemy()
bcrypt = Bcrypt()
DB_NAME = "database.db"
def create_app():
app = Flask(__name__)
app.config['SECRET_KEY'] = '0eeff27f9c89ab975e01c1eb5aeef5148b1810e9b690a77bedd94a261b3d9b98'
app.config['SQLALCHEMY_DATABASE_URI'] = f'postgresql://flask:Passw0rd!@postgres:5432/flask'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db.init_app(app)
bcrypt.init_app(app)
from views import views
from auth import auth
app.register_blueprint(views, url_prefix='/')
app.register_blueprint(auth, url_prefix='/')
from models import Users
create_database(app)
login_manager = LoginManager()
login_manager.init_app(app)
login_manager.login_view = 'auth.login'
@login_manager.user_loader
def load_user(user_id):
return Users.query.get(int(user_id))
return app
def create_database(app):
if not path.exists(DB_NAME):
db.create_all(app=app)
print('Created Database!')
if __name__ == '__main__':
app = create_app()
app.run(host='0.0.0.0')