-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathapp.py
More file actions
63 lines (48 loc) · 1.51 KB
/
app.py
File metadata and controls
63 lines (48 loc) · 1.51 KB
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
import click
from flask import Flask
from exts import db, mail, cache, csrf, avatars
import config
from flask_migrate import Migrate
from blueprints.cms import bp as cms_bp
from blueprints.front import bp as front_bp
from blueprints.user import bp as user_bp
from blueprints.media import bp as media_bp
import commands
from bbs_celery import make_celery
import hooks
import filters
import logging
app = Flask(__name__)
app.config.from_object(config.DevelopmentConfig)
db.init_app(app)
mail.init_app(app)
cache.init_app(app)
avatars.init_app(app)
# 设置日志级别
app.logger.setLevel(logging.INFO)
# CSRF保护
csrf.init_app(app)
migrate = Migrate(app, db)
# 注册蓝图
app.register_blueprint(cms_bp)
app.register_blueprint(front_bp)
app.register_blueprint(user_bp)
app.register_blueprint(media_bp)
# 添加命令
app.cli.command("create-permission")(commands.create_permission)
app.cli.command("create-role")(commands.create_role)
app.cli.command("create-test-front")(commands.create_test_user)
app.cli.command("create-board")(commands.create_board)
app.cli.command("create-test-post")(commands.create_test_post)
app.cli.command("create-admin")(commands.create_admin)
# 构建celery
celery = make_celery(app)
# 添加钩子函数
app.before_request(hooks.bbs_before_request)
app.errorhandler(401)(hooks.bbs_401_error)
app.errorhandler(404)(hooks.bbs_404_error)
app.errorhandler(500)(hooks.bbs_500_error)
# 添加模板过滤器
app.template_filter("email_hash")(filters.email_hash)
if __name__ == '__main__':
app.run()