-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
69 lines (50 loc) · 1.45 KB
/
main.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
from flask import Flask, render_template
from flask_login import LoginManager
from auth import auth
from database import db_session
from misc import misc
from models import User
from user import user
from utils import prod_config
app = Flask(__name__)
app.config.from_object(prod_config)
app.register_blueprint(auth)
app.register_blueprint(misc)
app.register_blueprint(user)
login_manager = LoginManager()
login_manager.init_app(app)
@login_manager.user_loader
def load_user(id):
return User.query.filter_by(id=id).one_or_none()
@app.route('/')
def index():
return render_template('index.html')
@app.teardown_appcontext
def close_session(exception=None):
db_session.remove()
@app.errorhandler(401)
def unauthorised_401(e):
data = {
"status": 401,
"title": "Unauthorised",
"detail": "You must be logged in to view this resource."
}
return render_template('error.html', **data)
@app.errorhandler(403)
def forbidden_403(e):
data = {
"status": 403,
"title": "Forbidden",
"detail": "Insufficient permission to access resource."
}
return render_template('error.html', **data)
@app.errorhandler(404)
def not_found_404(e):
data = {
"status": 404,
"title": "Not Found",
"detail": "The requested resource could not be found."
}
return render_template('error.html', **data)
if __name__ == '__main__':
app.run(host='127.0.0.1', port=8080, debug=True)