__init__.py 1.49 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.utils import make_celery
崔为之's avatar
崔为之 committed
21
from application.common import config
Weizhi Cui's avatar
Weizhi Cui committed
22 23 24


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

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

崔为之's avatar
崔为之 committed
41 42
    # Set universal config
    config.Universal = app.config
崔为之'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