-
Notifications
You must be signed in to change notification settings - Fork 0
/
__init__.py
46 lines (33 loc) · 1.21 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
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from os import path
from flask_login import LoginManager
# whatever mentioned in the file cna be imported to every other file as a library
db = SQLAlchemy()
DB_NAME = "flask_database.db"
def create_app():
app = Flask(__name__)
app.config['SECRET_KEY'] = 'rehan ahmed'
app.config['SQLALCHEMY_DATABASE_URI'] = f'sqlite:///{DB_NAME}'
db.init_app(app)
from .views import views
from .auth import auth
app.register_blueprint(views, url_prefix='/')
app.register_blueprint(auth, url_prefix='/')
# creating the database / implementing
from website.models import User , Note
create_database(app)
login_manager = LoginManager()
login_manager.login_view = 'auth.login'
login_manager.init_app(app)
@login_manager.user_loader
def load_user(id):
return User.query.get(int(id))
return app
# checks if a database exists, or creates one
def create_database(app):
if not path.exists('website/' + DB_NAME):
with app.app_context():
db.create_all()
print("Database Created")
# A database created in the Instance file