app.py 1.83 KB
Newer Older
Weizhi Cui's avatar
Weizhi Cui committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#!/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 13:49
# @File        : app.py
# @Description :
"""

from application import create_app

崔为之's avatar
崔为之 committed
15 16 17 18

def runserver():
    """
    This function creates a new instance of the Flask application and runs it.
崔为之's avatar
崔为之 committed
19 20 21 22 23 24 25

    It retrieves the host and port from the application configuration
    and uses these values when running the app.

    Please note that the Flask development server is not meant to be used in a
    production environment. It's intended to be used in development, where you
    can easily restart the server whenever you make changes to your code.
崔为之's avatar
崔为之 committed
26 27
    """

崔为之's avatar
崔为之 committed
28 29 30
    # Create a new instance of the Flask application.
    # The create_app() function should be defined elsewhere in your project,
    # and should return an instance of the Flask class.
崔为之's avatar
崔为之 committed
31 32
    app = create_app()

崔为之's avatar
崔为之 committed
33 34 35 36 37 38 39 40 41 42 43
    # Retrieve the server configuration from the Flask application config.
    # The 'Server' key is assumed to be a dictionary containing the keys 'IP' and 'Port'.
    cfg = app.config['Server']

    # Retrieve the host and port from the config.
    # If they're not present, default to '0.0.0.0' for the host and '5000' for the port.
    host = cfg.get('IP', '0.0.0.0')
    port = cfg.get('Port', 5000)

    # Run the Flask development server.
    app.run(host=host, port=port, use_reloader=False)
Weizhi Cui's avatar
Weizhi Cui committed
44 45


崔为之's avatar
崔为之 committed
46
if __name__ == '__main__':
崔为之's avatar
崔为之 committed
47 48 49 50 51 52 53 54
    """
    This condition is true if the script is run directly. 
    If the script is imported from another script, the condition is false.

    This allows you to use this script's functions without running the server 
    if you import this script from another script.
    """

崔为之's avatar
崔为之 committed
55 56
    # Only run the development server if the script is executed directly.
    runserver()