-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
47 lines (34 loc) · 1.11 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
from flask import Flask, render_template,session, g
import config
from exts import db,mail
from models import User
from blueprints import *
from flask_migrate import Migrate
app=Flask(__name__)
app.config.from_object(config)
db.init_app(app)
mail.init_app(app)
migrate=Migrate(app, db)
app.register_blueprint(auth_bp)
app.register_blueprint(qa_bp)
#blueprint is a way to organize the code
#beforer_request is a decorator that will run the function before the request
#after_request is a decorator that will run the function after the request
#before_first_request is a decorator that will run the function before the first request
#hook functions are functions that will run before or after the request
@app.before_request
def my_before_request():
user_id = session.get('user_id')
if user_id:
user = User.query.get(user_id)
setattr(g, 'user', user)
else:
setattr(g, 'user', None)
@app.context_processor
def my_context_processor():
return {'user':g.user}
@app.route('/')
def hello_world():
return render_template('index.html')
if __name__ == '__main__':
app.run(debug=True)