-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.py
80 lines (59 loc) · 1.97 KB
/
index.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
70
71
72
73
74
75
76
77
78
79
80
# -*- coding: utf-8 -*-
import os
from dotenv import load_dotenv
from flask import Flask
from flask.templating import render_template
from flask_cors import CORS
from backend.blueprints import routers
from backend.db import db
from backend.settings import config
load_dotenv()
class mainApp(Flask):
def __init__(self, *args, **options):
super().__init__(__name__, static_folder="./frontend/static",
template_folder="./frontend/templates",
*args, **options)
self.cors = CORS(self, resources={
"/*": {
"origins": "*"
}
})
self.db = db.init_app(self)
self.config.from_object(config["BaseConfig"])
# 移除 {% if %}空白
self.jinja_env.trim_blocks = True
self.jinja_env.lstrip_blocks = True
# 添加 blueprint
self.register_blueprint(routers)
# errors
@self.errorhandler(400)
def error_400(error):
"""400錯誤處理"""
return render_template("errors/400.html")
@self.errorhandler(403)
def error_403(error):
"""403錯誤處理"""
return render_template("errors/403.html")
@self.errorhandler(404)
def error_404(error):
"""404錯誤處理"""
return render_template("errors/404.html")
@self.errorhandler(413)
def error_413(error):
"""413錯誤處理"""
return render_template("errors/413.html")
@self.errorhandler(500)
def error_500(error):
"""500錯誤處理"""
return render_template("errors/500.html")
app = mainApp()
@app.route("/")
def index():
# random get 6*8 photos using api
return render_template("main/index.html", title="Hello World !", imgLinks=[{
"user": "",
"alt": "",
"uptime": "",
}])
if __name__ == "__main__":
app.run(debug=True, port=os.getenv("PORT") or 8080)