__init__.py 1.35 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 20 21 22
#!/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


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

崔为之's avatar
崔为之 committed
26 27 28 29 30 31 32 33 34 35 36
    :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
37 38
    init_plugs(app)

崔为之's avatar
崔为之 committed
39 40
    # 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
41 42
    init_views(app)

崔为之's avatar
崔为之 committed
43 44
    # 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
45 46
    init_script(app)

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