__init__.py 1.51 KB
Newer Older
Weizhi Cui's avatar
Weizhi Cui committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
# @Version     : Python 3.11.4
# @Software    : Sublime Text 4
# @Author      : StudentCWZ
# @Email       : StudentCWZ@outlook.com
# @Date        : 2023/10/28 12:11
# @File        : __init__.py
# @Description :
"""

import os

from flask import Flask

from application.extensions import init_plugs
from application.views import init_views
from application.script import init_script
崔为之's avatar
崔为之 committed
20
from application.common import global_config as gc
Weizhi Cui's avatar
Weizhi Cui committed
21 22 23


def create_app() -> Flask:
崔为之's avatar
崔为之 committed
24 25
    """
    This function creates and initializes a new Flask application.
Weizhi Cui's avatar
Weizhi Cui committed
26

崔为之's avatar
崔为之 committed
27 28 29 30 31 32 33 34 35 36 37
    :return: A new instance of a Flask application.
    """

    # Determine the path of the application root directory
    app_root_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "."))

    # Create a new Flask application instance
    app = Flask(app_root_path)

    # Initialize various plugins for the application.
    # This could include things like database connectors, authentication systems, etc.
Weizhi Cui's avatar
Weizhi Cui committed
38 39
    init_plugs(app)

崔为之's avatar
崔为之 committed
40
    # Set universal config
崔为之's avatar
崔为之 committed
41 42
    # 将 app.config 的内容复制到全局对象
    gc.config = app.config.copy()
崔为之's avatar
崔为之 committed
43

崔为之's avatar
崔为之 committed
44 45
    # Register the routes that this application will respond to.
    # This includes both the route URLs and the handlers for each route.
Weizhi Cui's avatar
Weizhi Cui committed
46 47
    init_views(app)

崔为之's avatar
崔为之 committed
48 49
    # Register any scripts or commands that can be run from the command line.
    # This could include data migration scripts, administrative tasks, etc.
Weizhi Cui's avatar
Weizhi Cui committed
50 51
    init_script(app)

崔为之's avatar
崔为之 committed
52
    # Return the fully initialized Flask application
Weizhi Cui's avatar
Weizhi Cui committed
53
    return app