app.py 1.71 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
    # 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']

崔为之's avatar
崔为之 committed
37
    # Retrieve the port from the config.
崔为之's avatar
崔为之 committed
38 39 40
    port = cfg.get('Port', 5000)

    # Run the Flask development server.
崔为之's avatar
崔为之 committed
41
    app.run(host='0.0.0.0', port=port, use_reloader=False)
Weizhi Cui's avatar
Weizhi Cui committed
42 43


崔为之's avatar
崔为之 committed
44
if __name__ == '__main__':
崔为之's avatar
崔为之 committed
45 46 47 48 49 50 51 52
    """
    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
53 54
    # Only run the development server if the script is executed directly.
    runserver()